-
Notifications
You must be signed in to change notification settings - Fork 48
Rank max learning rate #505
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
Draft
Hgherzog
wants to merge
5
commits into
main
Choose a base branch
from
cursor/rank-max-learning-rate-9827
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.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1a364cf
Add rank_max_lr feature for in-loop evaluations
cursoragent fa8117b
Use standard eval sweep LRs for rank_max_lr
cursoragent 0d53da1
Add launch script for rank_max_lr comparison experiments
cursoragent 7aeff69
Fix launch script: use .value/.unit for Duration overrides, 8k steps,…
cursoragent c06d182
simplify how this works
Hgherzog 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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| import torch.nn.functional as F | ||
| from einops import rearrange | ||
| from olmo_core.data.utils import get_rng | ||
| from olmo_core.distributed.utils import get_rank, get_world_size, is_distributed | ||
| from sklearn.metrics import accuracy_score | ||
| from torch.utils.data import DataLoader, TensorDataset | ||
| from tqdm import tqdm | ||
|
|
@@ -28,6 +29,20 @@ | |
| logger = getLogger(__name__) | ||
|
|
||
|
|
||
| RANK_MAX_LRS = [1e-4, 5e-4, 1e-3, 5e-3, 1e-2, 5e-2, 1e-1, 5e-1] | ||
|
|
||
|
|
||
| def get_rank_lr(rank: int, world_size: int) -> float | None: | ||
| """Get the learning rate for this rank from the standard eval sweep LRs. | ||
|
|
||
| Uses the same LRs as eval sweeps: [1e-4, 5e-4, 1e-3, 5e-3, 1e-2, 5e-2, 1e-1, 5e-1] | ||
| Returns None if rank >= len(RANK_MAX_LRS) (rank should not participate). | ||
| """ | ||
| if rank >= len(RANK_MAX_LRS): | ||
| return None | ||
| return RANK_MAX_LRS[rank] | ||
|
|
||
|
|
||
| class ProbeType(StrEnum): | ||
| """Enumeration of probe types for linear probing.""" | ||
|
|
||
|
|
@@ -135,15 +150,43 @@ def train_and_eval_probe( | |
| select_final_test_miou_based_on_epoch_of_max_val_miou: bool = False, | ||
| n_bootstrap: int = 0, | ||
| bootstrap_seed: int = 42, | ||
| rank_max_lr: bool = False, | ||
|
Collaborator
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. i feel like this should be true by default? |
||
| ) -> EvalTaskResult: | ||
| """Run a linear probe on the OlmoEarth Pretrain model. | ||
|
|
||
| When rank_max_lr=True, each rank uses a different LR from a log-spaced range | ||
| and the best result (max primary metric) is returned via all_reduce. | ||
|
|
||
| Returns: | ||
| Dictionary with keys: | ||
| - val_score: EvalResult for validation | ||
| - test_score: EvalResult for test, or None if no test set | ||
| - bootstrap_stats: Bootstrap statistics dict (empty dict if n_bootstrap == 0) | ||
| """ | ||
| # Rank-max LR: each rank uses a different LR from the standard sweep, then take max | ||
| # Auto-disable if world_size doesn't match the number of sweep LRs | ||
| use_rank_max = rank_max_lr and is_distributed() | ||
| if use_rank_max: | ||
| rank = get_rank() | ||
| world_size = get_world_size() | ||
| if world_size != len(RANK_MAX_LRS): | ||
| logger.warning( | ||
| f"rank_max_lr disabled: world_size={world_size} != {len(RANK_MAX_LRS)} " | ||
| f"(number of sweep LRs). Need exactly {len(RANK_MAX_LRS)} ranks." | ||
| ) | ||
| use_rank_max = False | ||
|
|
||
| if use_rank_max: | ||
| rank_lr = get_rank_lr(rank, world_size) | ||
| assert rank_lr is not None | ||
| effective_lr = rank_lr | ||
| logger.info( | ||
| f"Rank-max LR enabled: rank {rank}/{world_size} using lr={effective_lr:.6f} " | ||
| f"(sweep LRs: {RANK_MAX_LRS})" | ||
| ) | ||
| else: | ||
| effective_lr = lr | ||
|
|
||
| logger.info(f"Probe type {probe_type}") | ||
| if train_embeddings.shape[-1] != val_embeddings.shape[-1]: | ||
| raise ValueError("Embedding dims don't match.") | ||
|
|
@@ -204,7 +247,7 @@ def train_and_eval_probe( | |
| task_type=config.task_type, | ||
| probe=probe, | ||
| data_loader=data_loader, | ||
| lr=lr, | ||
| lr=effective_lr, | ||
| epochs=end_epoch, | ||
| total_epochs=epochs, | ||
| current_epoch=start_epoch, | ||
|
|
||
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
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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #!/bin/bash | ||
| # Comparison experiments for rank_max_lr feature | ||
| # Run MADOS eval every 500 steps for 8000 steps total | ||
| # Requires 8 GPUs for rank_max_lr to be active | ||
|
|
||
| # Baseline (without rank_max_lr) | ||
| python scripts/official/base.py launch mados-baseline ai2/jupiter-cirrascale-2 \ | ||
| --trainer.max_duration.value=8000 \ | ||
| --trainer.max_duration.unit=steps \ | ||
| --trainer.callbacks.downstream_evaluator.tasks_to_run='["mados"]' \ | ||
| --trainer.callbacks.downstream_evaluator.tasks.mados.eval_interval.value=500 \ | ||
| --trainer.callbacks.downstream_evaluator.tasks.mados.eval_interval.unit=steps \ | ||
| --trainer.callbacks.downstream_evaluator.tasks.mados.rank_max_lr=False \ | ||
| --launch.num_gpus=8 \ | ||
| --launch.priority=low | ||
|
|
||
| # With rank_max_lr (each GPU uses different LR, take max) | ||
| python scripts/official/base.py launch mados-rank-max-lr ai2/jupiter-cirrascale-2 \ | ||
| --trainer.max_duration.value=8000 \ | ||
| --trainer.max_duration.unit=steps \ | ||
| --trainer.callbacks.downstream_evaluator.tasks_to_run='["mados"]' \ | ||
| --trainer.callbacks.downstream_evaluator.tasks.mados.eval_interval.value=500 \ | ||
| --trainer.callbacks.downstream_evaluator.tasks.mados.eval_interval.unit=steps \ | ||
| --trainer.callbacks.downstream_evaluator.tasks.mados.rank_max_lr=True \ | ||
| --launch.num_gpus=8 \ | ||
| --launch.priority=low |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
world_size is not necessary for this function