-
Notifications
You must be signed in to change notification settings - Fork 52
Experiments: Add note, update script on removing W&B env var #2112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ngrayluna
wants to merge
2
commits into
main
Choose a base branch
from
experiments_shared_mode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,32 +166,70 @@ Within the primary node, initialize a W&B run with [`wandb.init()`](/models/ref/ | |
| 1. The `mode` parameter set to `"shared"` to enable shared mode. | ||
| 2. A unique label for [`x_label`](https://github.com/wandb/wandb/blob/main/wandb/sdk/wandb_settings.py#L638). You use the value you specify for `x_label` to identify which node the data is coming from in logs and system metrics in the W&B App UI. If left unspecified, W&B creates a label for you using the hostname and a random hash. | ||
| 3. Set the [`x_primary`](https://github.com/wandb/wandb/blob/main/wandb/sdk/wandb_settings.py#L660) parameter to `True` to indicate that this is the primary node. | ||
| <Info> | ||
| `x_primary=True` distinguishes a primary node from worker nodes. Primary nodes are the only nodes that upload files shared across nodes such as configuration files, telemetry and more. Worker nodes do not upload these files. | ||
| </Info> | ||
| 4. Optionally provide a list of GPU indexes ([0,1,2]) to `x_stats_gpu_device_ids` to specify which GPUs W&B tracks metrics for. If you do not provide a list, W&B tracks metrics for all GPUs on the machine. | ||
|
|
||
| Make note of the run ID of the primary node. Each worker node needs the run ID of the primary node. | ||
|
|
||
| <Note> | ||
| `x_primary=True` distinguishes a primary node from worker nodes. Primary nodes are the only nodes that upload files shared across nodes such as configuration files, telemetry and more. Worker nodes do not upload these files. | ||
| </Note> | ||
| <Tip> | ||
| Store the run ID of the primary node in an environment variable (e.g., WANDB_RUN_ID) that worker nodes can read. For example: | ||
| ```python | ||
| import wandb | ||
| import os | ||
|
|
||
| # Primary node | ||
| run = wandb.init( ... ) | ||
| os.environ['WANDB_RUN_ID'] = run.id | ||
|
|
||
| # Worker node | ||
| run = wandb.init( ... , id=os.environ['WANDB_RUN_ID']) | ||
| ``` | ||
| </Tip> | ||
|
|
||
|
|
||
| For each worker node, initialize a W&B run with [`wandb.init()`](/models/ref/python/functions/init) and provide the following: | ||
|
|
||
| <Tip> | ||
| Use the same entity and project for all nodes. Run IDs are scoped to an `entity/project` combination, so mismatched values will create a new run instead of joining the existing one. | ||
| </Tip> | ||
|
|
||
| 1. A `wandb.Settings` object to the `settings` parameter (`wandb.init(settings=wandb.Settings()`) with: | ||
| * The `mode` parameter set to `"shared"` to enable shared mode. | ||
| * A unique label for `x_label`. You use the value you specify for `x_label` to identify which node the data is coming from in logs and system metrics in the W&B App UI. If left unspecified, W&B creates a label for you using the hostname and a random hash. | ||
| * Set the `x_primary` parameter to `False` to indicate that this is a worker node. | ||
| 2. Pass the run ID used by the primary node to the `id` parameter. | ||
| 3. Optionally set [`x_update_finish_state`](https://github.com/wandb/wandb/blob/main/wandb/sdk/wandb_settings.py#L772) to `False`. This prevents non-primary nodes from updating the [run's state](/models/evaluate-models/#run-states) to `finished` prematurely, ensuring the run state remains consistent and managed by the primary node. | ||
|
|
||
| <Note> | ||
| * Use the same entity and project for all nodes. This helps ensure the correct run ID is found. | ||
| * Consider defining an environment variable on each worker node to set the run ID of the primary node. | ||
| </Note> | ||
|
|
||
|
|
||
| The following sample code demonstrates the high level requirements for tracking multiple processes to a single run: | ||
|
|
||
| <Warning> | ||
| **Environment variable inheritance** | ||
|
|
||
| Worker processes may inherit W&B-related environment variables (such as `WANDB_SERVICE`) from parent processes in distributed environments. This can cause | ||
| initialization conflicts. | ||
|
|
||
| Clear inherited W&B environment variables (such as `WANDB_SERVICE`) before calling `wandb.init()` on worker nodes to avoid initialization conflicts: | ||
|
|
||
| ```python | ||
| import os | ||
| os.environ.pop('WANDB_SERVICE', None) | ||
| ``` | ||
| </Warning> | ||
|
Comment on lines
+209
to
+221
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oof, this one might be necessary in some cases, but that's definitely a bug on our side. Not sure about including this in the docs as it's a super janky thing to ask users to do. |
||
|
|
||
| ```python | ||
| import os | ||
| import wandb | ||
|
|
||
| # Clear inherited W&B environment variables to avoid environment conflicts. | ||
| # Add this line before calling wandb.init() on worker nodes. | ||
| os.environ.pop('WANDB_SERVICE', None) | ||
|
|
||
| # Specify your W&B entity and project. | ||
| # Recommened to use the same entity and project for all nodes. | ||
| entity = "<team_entity>" | ||
| project = "<project_name>" | ||
|
|
||
|
|
@@ -223,7 +261,12 @@ run = wandb.init( | |
| run = wandb.init( | ||
| entity=entity, # Use the same entity as the primary node | ||
| project=project, # Use the same project as the primary node | ||
| settings=wandb.Settings(x_label="rank_2", mode="shared", x_primary=False), | ||
| settings=wandb.Settings( | ||
| x_label="rank_2", | ||
| mode="shared", | ||
| x_primary=False, | ||
| x_update_finish_state=False, # Prevent worker from prematurely finishing the run | ||
| ), | ||
| id=run_id, | ||
| ) | ||
| ``` | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example feels misleading to me because it looks like those statements run in the same script. I'm not sure this form is practical, since it requires somehow starting up worker nodes from the primary node's script to pass on the generated run ID.
The environment variable
WANDB_RUN_IDis read automatically bywandb, and generally users should not readWANDB_variables or use them for custom purposes. I also wouldn't advise anyone to modifyos.environat runtime, since changes might not be detected.The essence of the original tip is to (1) generate your own ID and (2) set the
WANDB_RUN_IDenvironment variable however you do it in the framework you're using to orchestrate the nodes. There's no general code sample we can provide as it's highly dependent on the user's setup.