Skip to content

benchmark: 2-type pref_type with PARTITION_SCAN dispatch#5

Merged
hmgaudecker merged 1 commit into
mainfrom
feature/benchmark-2-pref-types-partition
Apr 22, 2026
Merged

benchmark: 2-type pref_type with PARTITION_SCAN dispatch#5
hmgaudecker merged 1 commit into
mainfrom
feature/benchmark-2-pref-types-partition

Conversation

@hmgaudecker

Copy link
Copy Markdown
Member

Summary

  • Adds BenchmarkPrefType (2 categories) next to production PrefType (3 categories) and opts aca_model.benchmark.create_benchmark_model() into DispatchStrategy.PARTITION_SCAN on the benchmark's pref_type grid.
  • Threads a pref_type_grid kwarg through create_model / build_all_regimes / build_grids so callers can override without touching production defaults.
  • get_benchmark_params() truncates the three pref_type-indexed pd.Series (discount_factor_by_type, coefficient_rra, consumption_weight) to 2 rows so they align with BenchmarkPrefType. 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.
  • End-to-end smoke on CPU: `create_benchmark_model()` + `get_benchmark_params()` + `simulate()` on tiny grids (20 subjects × 45 periods → 900 rows). Partition grid reports `categories=('type_0', 'type_1')`, `dispatch=partition_scan`.
  • pylcm PR #331 benchmark-pr — aca-baseline wall time should drop (see pylcm commit `a32631c`).

Compatibility

Requires pylcm with `DispatchStrategy` exported from `lcm` (PR #331).

🤖 Generated with Claude Code

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>
@hmgaudecker hmgaudecker merged commit d277772 into main Apr 22, 2026
1 check failed
@hmgaudecker hmgaudecker deleted the feature/benchmark-2-pref-types-partition branch April 22, 2026 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant