Float32 fidelity: which float64 lectures need float64, and can the heaviest step drop to float32?

Đang mở
#11 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python

Hướng nghiên cứu

Start with lectures/run_lecture.py and the lecture implementations listed in the issue; compare each lecture's recorded answers and convergence behavior under --dtype float32 and --dtype float64. Then examine aiyagari_jax's get_greedy for the mixed-precision variant, measuring policy changes, runtime, and equilibrium capital across the stated grids and devices. Done means producing the per-lecture and mixed-precision result tables, saving results under lectures/results/<host>/<date>/, and recording findings in the benchmarks repository.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Run the 13 float64 lectures in lecture-jax in float32 and record whether each still reaches its answer, then try a mixed-precision version of aiyagari_jax's greedy step. The aim is to know where QuantEcon's JAX code needs float64, and where it is a precaution.

Why

  • The lectures don't say what float64 protects. 13 of the 29 lectures in lecture-jax turn it on, each with the same sentence, "to increase the precision". None says what goes wrong without it.
  • #3 found that float32 fails aiyagari_jax in two ways, and neither is a slightly worse answer.
    • Two of its 50 solves stall at an error of about 2.5e-4, against the lecture's tolerance of 1e-4, and run to the 10,000-iteration cap. That makes the lecture about 12× slower as used.
    • On the TITAN RTX at a 5,000-point grid, its values went NaN in all three runs, from a bicgstab breakdown (QuantEcon/project-benchmarks-jax#5). The loop's test error > tol is false for NaN, so it stopped after two iterations with a policy wrong almost everywhere, and raised no error. Both CPUs stayed finite.
    • When float32 did converge, equilibrium capital matched float64 to 2e-5.
  • ifp_egm_jax converges in float32, to within 1.6e-4 of the float64 policy.
  • So float32 fails by not finishing, or by failing silently, and the failure can depend on the device. Two lectures don't say which of the other eleven share that.
  • #4 runs these lectures in float32 for time. This issue asks whether the answer survives.
  • The step that float64 makes expensive may not need it. In dense discrete choice the costly step recomputes rewards and takes the maximum over choices: 26.8× slower in float64 than in float32 on the TITAN RTX (#6). That step only has to pick the best choice. The value update, the convergence test, policy evaluation and the equilibrium search could stay in float64.

Part 1: the 13 lectures in float32

Lecture Solver and tolerance, as written
aiyagari_jax Policy iteration, 1e-4; equilibrium capital by bisection, xtol 1e-4
arellano_jax Joint iteration on the repay and default value functions, 1e-8
hopenhayn Value function iteration, 1e-6; the entry price by bisection, 1e-4
ifp_egm_jax Endogenous grid method, 1e-5
inventory_ssd Value function iteration, 1e-6
jax_intro_jax None; it turns float64 on to show the difference
job_search Value function iteration, 1e-4
markov_asset_jax A linear solve for the price-dividend ratio, after a spectral-radius check
mle_jax Newton–Raphson, 1e-3 and 1e-5
newtons_method Newton's method, 1e-5; float64 is turned on in exercise 1's solution, for tolerances of 1e-7 and 1e-15
opt_invest Value function and optimistic policy iteration, 1e-5
opt_savings_1 Value function iteration, 1e-5
opt_savings_2 Value function and optimistic policy iteration, 1e-5

Also the two float32 lectures that solve to a tolerance, overborrowing (1e-5) and lucas_model_jax (1e-6): whether they meet it, or stop at their iteration cap.

Method:

  • lectures/run_lecture.py with --dtype float32 and --dtype float64, at the lecture-jax commit #4 used. Each of the 13 has exactly one jax_enable_x64 line, as --dtype float32 requires.
  • --record each lecture's answer: the equilibrium values, prices, estimates or policies it reports. Choosing the expressions lecture by lecture is part of the work.
  • For each solve: whether it met its tolerance or stopped at its cap, and how many iterations it took. Where a solver doesn't return these, read them from its printed output.
  • Check every recorded value for NaN and Inf. Don't rely on a loop's exit: a NaN error ends while error > tol as if it had converged.
  • One run per configuration, and three where results vary between runs.

Platforms:

Device Why
M6 CPU, qe-mini1, with its agents paused Seconds per lecture; the CPU answer
TITAN RTX, qe-wharton1-gpu, card 0b:00.0 The silent NaN appeared only on the GPU
T4, RunsOn g4dn.2xlarge The lectures' CI device, if it is cheap to add to #4's job

Result: one table, lecture by device, giving whether float32 converges (yes, stops at its cap, NaN, or raises), the largest gap from float64 in the recorded answers, and whether that gap is within the lecture's own tolerance.

Part 2: a mixed-precision greedy step for aiyagari_jax

  • The variant: with float64 on, get_greedy casts to float32, computes rewards and the argmax over next-period assets, and returns the policy. The value function, get_value's bicgstab solve, the convergence test and the equilibrium bisection stay in float64.
  • Then one float64 greedy step at the converged solution, counting the policy points that change. That catches choices decided by a near-tie.
  • At the grids #3 used, 200 to 10,000 asset points, on the TITAN RTX and the M6.
  • Record: time per policy-iteration loop, against pure float64 and pure float32; the policy points that differ from float64, and by how many grid steps; the gap in equilibrium capital; iterations to converge.
  • If it is ready in time, add it to #1's Phase 2 runs. A Blackwell workstation card does float64 at 1:64 of float32, so that is where the float32 step would matter most.

What the results would change

If Then
A float64 lecture reaches its answer in float32, within its tolerance, on every device Float64 is a precaution there. The lecture can say so, or say what it guards against
A lecture stalls, goes NaN, or moves its answer past its tolerance in float32 It needs float64 as written, and the lecture can say why
The mixed step gives float64's answer at a fraction of float64's cost Research-scale discrete-choice models can run their heavy step at a card's float32 rate. That changes which card suits them, which project-compute weighs
It doesn't Dense discrete choice needs float64 throughout, and a card's float64 rate decides

Deliverables

  • the results, under lectures/results/<host>/<date>/ as #4's are;
  • the per-lecture table, and Part 2's table of time and gaps;
  • a finding in QuantEcon/project-benchmarks-jax's findings/, with its hardware consequence going to project-compute.

Related

  • #1, the precision experiment, with #3 and #6, which measured aiyagari_jax's float32 failures and float64's cost by kernel type
  • #4, the whole-lecture run, which times these lectures in float32
  • QuantEcon/project-benchmarks-jax#5, the bicgstab breakdown

🤖 Generated with Claude Code

Ngôn ngữ chính
Python
Star
0
Fork
1
Merge trung bình
3 giờ 29 phút
Pull request đã merge (30 ngày)
64

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của QuantEcon/benchmarks

Tất cả issue của QuantEcon/benchmarks

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.