Repository navigation
fix(windows): make environment set from Rust reach MLX's getenv - #2805
Merged
Merged
Conversation
On Windows `std::env::set_var` only calls `SetEnvironmentVariableW`, and the C runtime's `getenv`, which MLX reads, keeps its own copies. Every default mlxcel writes for MLX was inert there: the graph and SDPA cache capacities, the per-family graph budget, the Gemma 4 graph capture switch and the tuned kernel knobs. `mlxcel_core::native_env` also calls `_wputenv_s`, in the one UCRT that Rust, the bridge, MLX and the nvcc objects share (all `/MD`). Production writes go through it, and `check_native_env_writes.py` fails CI on a direct one. Other platforms still only make the `std::env` call. Tests read back through the bridge and `mlx::core::env::get_var`; 5 of 8 fail without the `_wputenv_s` call. A debug line reports each audited variable as native code reads it. Closes #2803
3 of 8 tasks
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.
On Windows
std::env::set_vardoes not update the C runtime'sgetenv, which MLX reads, so every default mlxcel writes for MLX was inert there.mlxcel_core::native_envalso calls_wputenv_s, in the one UCRT that Rust, the bridge, MLX and the nvcc objects share (allMD_DynamicRelease, measured). Production writes go through it, andscripts/ci/check_native_env_writes.pyfails CI on a direct one. Other platforms still only make thestd::envcall.Audit
MLX_USE_CUDA_GRAPHSloading/mod.rsdevice.cppMLX_CUDA_GRAPH_CACHE_SIZEhardware.rslru_cache.hMLX_CUDA_SDPA_CACHE_SIZEhardware.rslru_cache.hMLX_MAX_OPS_PER_BUFFERcuda_graph_budget.rs,hardware.rs(Metal)get_graph_limitsMLX_MAX_MB_PER_BUFFERcuda_graph_budget.rsget_graph_limitsMLX_PTX_CACHE_DIRensure_persistent_ptx_cacheptx_cache_dir_win.h(wide)MLXCEL_QMM_TILE_Mcuda_kernel_knobs.rsqmm_sm80.cuMLXCEL_QMV_MULTIROW_MAX_ROWScuda_kernel_knobs.rsqmv.cuMLXCEL_KV_BOUNDARY_V_LAYERSandMLXCEL_PREFILL_CHUNKare read by Rust only; they use the helper so the guard has one rule.MLX_ENABLE_TF32and themlx_server.rswrites are test-only.Behavior change on Windows
Gemma 4 runs with graph capture off, Laguna gets the 100 ops and 1000 "MB" budget on compute capability 12.1, and both cache capacities are 2000. The N1X serving A/B is run separately by the owner; no serving benchmark ran here.
Validation
On an RTX Spark N1X: 5 of 8
native_envtests fail without the_wputenv_scall and 8 of 8 pass with it, reading through the bridge andmlx::core::env::get_var.cuda_ptx_cache_trust_windowspasses 22 of 22.RUST_LOG=mlxcel_core::native_env=debugshowed the expected values inmlxcelandmlxcel-serverfor config-only llama, gemma4 and laguna directories, and an operator value still wins. Not run: POSIX locally (CI covers it), weights on these paths, and a cache grown past 400 entries.Closes #2803