Skip to content

Conversation

@jstac
Copy link
Contributor

@jstac jstac commented Dec 4, 2025

Summary

This PR adds JIT compilation to the train_network function in ifp_dl.md and optimizes performance parameters, resulting in significant speedups.

Key Changes

JIT Compilation:

  • Added @jax.jit decorator with static_argnames=('config', 'loss_fn')
  • Replaced Python for loop with jax.lax.fori_loop
  • Removed print statements (not JIT-compatible)
  • Used value_history.at[i].set() for in-place updates
  • Replaced conditional if statements with jnp.where
  • Used jax.tree.map for PyTree-aware parameter updates

Performance Optimizations:

  • Reduced path_length from 320 to 200 (35% faster)
  • Reduced num_paths from 220 to 100
  • Added warmup calls before timing measurements
  • Added block_until_ready() for accurate timing

Code Quality:

  • Added type hints and inline comments to function signatures
  • Fixed grammar in docstrings
  • Removed verbose Args/Returns sections from several docstrings

Performance Results

With the optimized configuration:

  • Cake eating model: 0.49s (was ~0.82s) - ~40% faster
  • IFP model: 3.91s (was ~10s+) - ~60% faster

Solution quality remains excellent with the reduced path lengths.

🤖 Generated with Claude Code

jstac and others added 2 commits December 4, 2025 17:04
Updated function signatures to include type hints and inline comments
for improved code readability and consistency:
- initialize_layer: Added type hints for in_dim, out_dim, and key
- initialize_network: Added type hints for key and layer_sizes
- forward: Added type hints for params and a (asset level)
- compute_lifetime_value: Added type hints for all parameters
- K: Added type hints and removed Args/Returns from docstring
- solve_model: Added type hints and removed Args/Returns from docstring
- compute_lifetime_value_ifp: Added type hints and removed Args/Returns

Also fixed grammar in initialize_layer docstring ("a the" → "the").

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Refactored train_network for JIT compilation with significant performance
improvements:

- Added @jax.jit decorator with static_argnames for config and loss_fn
- Replaced Python for loop with jax.lax.fori_loop for JIT compatibility
- Removed print statements (not JIT-compatible)
- Used value_history.at[i].set() to accumulate history in-place
- Replaced if statements with jnp.where for conditional logic
- Used jax.tree.map for conditionally updating best_params PyTree

Performance optimizations:
- Reduced path_length from 320 to 200 (35% faster)
- Reduced num_paths from 220 to 100 (additional speedup)
- Added warmup calls to trigger JIT compilation before timing
- Added block_until_ready() for accurate timing measurements

Results with new configuration:
- Cake eating model: 0.49s (was ~0.82s)
- IFP model: 3.91s (was ~10s+)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@netlify
Copy link

netlify bot commented Dec 4, 2025

Deploy Preview for incomparable-parfait-2417f8 ready!

Name Link
🔨 Latest commit fa785e8
🔍 Latest deploy log https://app.netlify.com/projects/incomparable-parfait-2417f8/deploys/693149da1fb66a0008509210
😎 Deploy Preview https://deploy-preview-263--incomparable-parfait-2417f8.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link

github-actions bot commented Dec 4, 2025

@github-actions github-actions bot temporarily deployed to pull request December 4, 2025 08:51 Inactive
@github-actions github-actions bot temporarily deployed to pull request December 4, 2025 08:56 Inactive
@jstac jstac merged commit b99eb52 into main Dec 4, 2025
7 checks passed
@jstac jstac deleted the ifpjit branch December 4, 2025 08:56
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.

2 participants