benchmark: 2-type pref_type with PARTITION_SCAN dispatch#5
Merged
Conversation
Makes `aca_model.benchmark.create_benchmark_model()` faster by: 1. Substituting a `BenchmarkPrefType` with 2 categories for the production 3-type `PrefType`. Drops ~33% of the compile + execution volume across the 18-regime DAG without changing the kernel shape being exercised. 2. Setting `dispatch=DispatchStrategy.PARTITION_SCAN` on the benchmark's pref_type grid. Lifts the dim out of the state-action space and sweeps it at the top level via `jax.lax.scan`. Bounds GPU memory and keeps the axis JAX-visible so a future `shard_map` multi-device swap is a one-liner. 3. No `batch_size != 0` on any grid: `BENCHMARK_GRID_CONFIG` already sets `n_assets_batch_size=0`, and no other grid uses a chunked lax.map. Mechanics: - Adds `BenchmarkPrefType` next to `PrefType` in `agent/preferences.py`. - `Grids` gains a `pref_type` field; `build_grids`, `build_all_regimes`, and `create_model` accept a `pref_type_grid: DiscreteGrid | None` kwarg (default = `DiscreteGrid(PrefType)`, i.e. production unchanged). - `benchmark.py` passes a `DiscreteGrid(BenchmarkPrefType, dispatch=PARTITION_SCAN)` through. - `get_benchmark_params()` truncates the three pref_type-indexed `pd.Series` in the frozen-params pickle (`discount_factor_by_type`, `coefficient_rra`, `consumption_weight`) to two rows so they align with `BenchmarkPrefType`'s two categories. The pickle itself stays unchanged so no regeneration is needed. Verified: 199 tests pass on py314; end-to-end smoke test on CPU solves + simulates in 450 s with 20 subjects (tiny benchmark grids). Requires pylcm with `DispatchStrategy` (PR #331). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BenchmarkPrefType(2 categories) next to productionPrefType(3 categories) and optsaca_model.benchmark.create_benchmark_model()intoDispatchStrategy.PARTITION_SCANon the benchmark's pref_type grid.pref_type_gridkwarg throughcreate_model/build_all_regimes/build_gridsso callers can override without touching production defaults.get_benchmark_params()truncates the three pref_type-indexedpd.Series(discount_factor_by_type,coefficient_rra,consumption_weight) to 2 rows so they align withBenchmarkPrefType. The frozen pickle is unchanged.Why
The ASV benchmark needs a fast stand-in for the full aca-baseline model. Cutting pref_type from 3 → 2 categories drops ~33% of the compile + execution volume across the 18-regime DAG without changing the kernel shape. Partition-lifting the dim keeps GPU memory bounded and lines up with the recommended production setting (see the discussion on pylcm PR #331).
Test plan
pixi run -e py314 pytest tests -n auto— 199 tests pass.Compatibility
Requires pylcm with `DispatchStrategy` exported from `lcm` (PR #331).
🤖 Generated with Claude Code