fix: don't copy the driver environment into the caller's env_vars dict - #4274
Open
David-Wu1119 wants to merge 1 commit into
Open
David-Wu1119 wants to merge 1 commit into
David-Wu1119 wants to merge 1 commit into
Conversation
RayWorkerGroup._create_workers_from_bundle_indices merged os.environ into
the env_vars dict it was given. Policy and value workers pass the dict from
the run config (e.g. policy.dtensor_cfg.env_vars), and PolicyConfig is a
TypedDict stored as-is inside the pydantic MasterConfig, so after worker
creation the config held every driver environment variable. GRPO then
writes master_config.model_dump() to each checkpoint's config.yaml, which
put the whole environment, including tokens, into every checkpoint.
Build a new dict instead ({**os.environ, **env_vars}, caller values still
win) and add a test that the argument is left unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: David-Wu1119 <133224895+David-Wu1119@users.noreply.github.com>
This branch has not been deployed
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.
What does this PR do ?
Stops
RayWorkerGroupfrom writing the driver's environment into theenv_varsdict it is given, which put every environment variable (tokens included) into each checkpoint'sconfig.yaml._create_workers_from_bundle_indicesmergedos.environintoenv_varsin place. That dict often belongs to the run config:lm_policy.pypassesconfig["dtensor_cfg"].get("env_vars", {})unchanged (the Megatron path already copies it withdict(...));lm_value.pyandteacher_worker_group.pydo the same.PolicyConfig/DTensorConfigare TypedDicts stored as-is inside the pydanticMasterConfig, somaster_config.policy[...]["env_vars"]is that same dict object (checked with pydantic 2.13.5).master_configwith each checkpoint (checkpointer.init_tmp_checkpoint(..., master_config)→yaml.safe_dump(run_config.model_dump(mode="json"))inutils/checkpoint.py).So a run that sets, for example,
policy.dtensor_cfg.env_vars: {NCCL_DEBUG: WARN}ends up with the whole driver environment (HF_TOKEN,WANDB_API_KEY, cloud credentials, ...) under that key in every checkpoint'sconfig.yaml.The change builds a new dict instead,
env_vars = {**os.environ, **env_vars}, so caller values still take precedence and workers see exactly what they did before.Issues
None filed.
Usage
No API change.
Before your PR is "Ready for review"
Pre checks:
Additional Information
test_env_vars_argument_is_not_modifiedintests/unit/distributed/test_worker_groups.py(CPU Ray cluster, like its neighbours). Onmainit fails with the dict holding the full environment; with this change it passes.tests/unit/distributed/test_worker_groups.pyon this branch: 29 passed, 1 skipped (local CPU Ray, Python 3.13, torch 2.11), includingtest_environment_variable_precedence_full.pyrefly check nemo_rl/distributed/worker_groups.pyreports the same 5 findings onmainand on this branch. I couldn't run theuv-based hooks as configured, because Python 3.13.14 isn't available for macOS arm64 yet.🤖 Generated with Claude Code