-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add AutoTP=2 smoke test config and script #1004
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ac68cb7
Add AutoTP=2 smoke test config and script
delock 6e1791d
Enable AutoTP + ZeRO-3 for teacher and student; fix teacher ZeRO-3 gate
delock 8bcc48b
Address review: fix DistributedSampler rank and use HF model IDs
delock 6cc7b76
Guard autotp_size()==0 in pure-DP mode
delock 5dae501
Merge branch 'master' into gma/opsd-autotp
delock 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
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,23 @@ | ||
| { | ||
| "bf16": { | ||
| "enabled": true | ||
| }, | ||
| "zero_optimization": { | ||
| "stage": 0 | ||
| }, | ||
| "tensor_parallel": { | ||
| "autotp_size": 2 | ||
| }, | ||
| "optimizer": { | ||
| "type": "AdamW", | ||
| "params": { | ||
| "lr": 1e-6, | ||
| "betas": [0.9, 0.95], | ||
| "eps": 1e-8, | ||
| "weight_decay": 0.0, | ||
| "torch_adam": true | ||
| } | ||
| }, | ||
| "gradient_clipping": 1.0, | ||
| "wall_clock_breakdown": false | ||
| } |
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,36 @@ | ||
| { | ||
| "bf16": { | ||
| "enabled": true | ||
| }, | ||
| "zero_optimization": { | ||
| "stage": 3, | ||
| "offload_optimizer": { | ||
| "device": "cpu" | ||
| }, | ||
| "offload_param": { | ||
| "device": "cpu" | ||
| }, | ||
| "overlap_comm": true, | ||
| "contiguous_gradients": true, | ||
| "reduce_bucket_size": 5e7, | ||
| "stage3_prefetch_bucket_size": 5e7, | ||
| "stage3_param_persistence_threshold": 1e6, | ||
| "stage3_max_live_parameters": 1e9, | ||
| "stage3_max_reuse_distance": 1e9 | ||
| }, | ||
| "tensor_parallel": { | ||
| "autotp_size": 2 | ||
| }, | ||
| "optimizer": { | ||
| "type": "AdamW", | ||
| "params": { | ||
| "lr": 1e-6, | ||
| "betas": [0.9, 0.95], | ||
| "eps": 1e-8, | ||
| "weight_decay": 0.0, | ||
| "torch_adam": true | ||
| } | ||
| }, | ||
| "gradient_clipping": 1.0, | ||
| "wall_clock_breakdown": false | ||
| } |
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,45 @@ | ||
| { | ||
| "student": { | ||
| "model_name_or_path": "Qwen/Qwen2.5-0.5B-Instruct", | ||
| "dtype": "bfloat16", | ||
| "trust_remote_code": false | ||
| }, | ||
| "teacher": { | ||
| "model_name_or_path": "Qwen/Qwen2.5-1.5B-Instruct", | ||
| "dtype": "bfloat16", | ||
| "trust_remote_code": false, | ||
| "offload_to_cpu": false, | ||
| "autotp_size": 2 | ||
| }, | ||
| "rollout": { | ||
| "engine": "hybrid_engine", | ||
| "max_prompt_length": 128, | ||
| "max_response_length": 32, | ||
| "temperature": 0, | ||
| "n_samples_per_prompt": 1 | ||
| }, | ||
| "distillation": { | ||
| "loss_type": "reverse_kl", | ||
| "temperature": 1.0, | ||
| "chunk_size": 128 | ||
| }, | ||
| "training": { | ||
| "micro_batch_size_per_gpu": 1, | ||
| "gradient_accumulation_steps": 1, | ||
| "learning_rate": 1e-6, | ||
| "weight_decay": 0.0, | ||
| "num_train_epochs": 1, | ||
| "max_steps": 3, | ||
| "warmup_steps": 0, | ||
| "save_steps": 10000, | ||
| "logging_steps": 1, | ||
| "save_dir": "./opsd_smoke_autotp_ckpt", | ||
| "seed": 42 | ||
| }, | ||
| "data": { | ||
| "path": "data/prompts.jsonl", | ||
| "prompt_field": "prompt", | ||
| "shuffle": true | ||
| }, | ||
| "deepspeed_config": "configs/smoke_ds_zero0_autotp2.json" | ||
| } |
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,45 @@ | ||
| { | ||
| "student": { | ||
| "model_name_or_path": "Qwen/Qwen2.5-0.5B-Instruct", | ||
| "dtype": "bfloat16", | ||
| "trust_remote_code": false | ||
| }, | ||
| "teacher": { | ||
| "model_name_or_path": "Qwen/Qwen2.5-1.5B-Instruct", | ||
| "dtype": "bfloat16", | ||
| "trust_remote_code": false, | ||
| "offload_to_cpu": true, | ||
| "autotp_size": 2 | ||
| }, | ||
| "rollout": { | ||
| "engine": "hybrid_engine", | ||
| "max_prompt_length": 128, | ||
| "max_response_length": 32, | ||
| "temperature": 0, | ||
| "n_samples_per_prompt": 1 | ||
| }, | ||
| "distillation": { | ||
| "loss_type": "reverse_kl", | ||
| "temperature": 1.0, | ||
| "chunk_size": 128 | ||
| }, | ||
| "training": { | ||
| "micro_batch_size_per_gpu": 1, | ||
| "gradient_accumulation_steps": 1, | ||
| "learning_rate": 1e-6, | ||
| "weight_decay": 0.0, | ||
| "num_train_epochs": 1, | ||
| "max_steps": 3, | ||
| "warmup_steps": 0, | ||
| "save_steps": 10000, | ||
| "logging_steps": 1, | ||
| "save_dir": "./opsd_smoke_autotp_zero3_ckpt", | ||
| "seed": 42 | ||
| }, | ||
| "data": { | ||
| "path": "data/prompts.jsonl", | ||
| "prompt_field": "prompt", | ||
| "shuffle": true | ||
| }, | ||
| "deepspeed_config": "configs/smoke_ds_zero3_offload_autotp2.json" | ||
| } |
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,5 @@ | ||
| #!/bin/bash | ||
| # Smoke test: OPSD with AutoTP=2 (requires 2 GPUs) | ||
| # Usage: bash scripts/smoke_autotp.sh | ||
| export PYTHONPATH=. | ||
| deepspeed --num_gpus 2 main.py --config configs/smoke_hybrid_autotp.json |
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,62 @@ | ||
| """Isolated student test: AutoTP + ZeRO-3 (+offload) forward/backward/step. | ||
|
|
||
| Env knobs: | ||
| STUDENT_MODEL (default local path), OFFLOAD (1/0), AUTOTP (int) | ||
| Launch: deepspeed --num_gpus N test_student_autotp_zero3.py | ||
| """ | ||
| import os | ||
| import sys | ||
|
|
||
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | ||
|
|
||
| import torch | ||
| import deepspeed | ||
| from deepspeed.accelerator import get_accelerator | ||
| from transformers import AutoModelForCausalLM | ||
|
|
||
| MODEL = os.environ.get("STUDENT_MODEL", "/root/autodl-tmp/models/Qwen2.5-0.5B-Instruct") | ||
|
tohtana marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def build_ds_config(): | ||
| offload = os.environ.get("OFFLOAD", "1") == "1" | ||
| autotp = int(os.environ.get("AUTOTP", "2")) | ||
| z = {"stage": 3} | ||
| if offload: | ||
| z["offload_param"] = {"device": "cpu"} | ||
| z["offload_optimizer"] = {"device": "cpu"} | ||
| return { | ||
| "train_micro_batch_size_per_gpu": 1, | ||
| "bf16": {"enabled": True}, | ||
| "zero_optimization": z, | ||
| "tensor_parallel": {"autotp_size": autotp}, | ||
| "optimizer": {"type": "AdamW", "params": {"lr": 1e-6, "torch_adam": True}}, | ||
| } | ||
|
|
||
|
|
||
| def main(): | ||
| deepspeed.init_distributed() | ||
| model = AutoModelForCausalLM.from_pretrained(MODEL, dtype=torch.bfloat16) | ||
| engine, *_ = deepspeed.initialize( | ||
| model=model, model_parameters=model.parameters(), config=build_ds_config() | ||
| ) | ||
|
|
||
| dev = get_accelerator().current_device_name() | ||
| input_ids = torch.tensor([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]], device=dev) | ||
| attn = torch.ones_like(input_ids) | ||
| out = engine(input_ids=input_ids, attention_mask=attn) | ||
| loss = out.logits.float().mean() | ||
| engine.backward(loss) | ||
| engine.step() | ||
|
|
||
| if deepspeed.comm.get_rank() == 0: | ||
| print( | ||
| f"STUDENT_OK loss={loss.item():.4f} " | ||
| f"mem={torch.cuda.max_memory_allocated()/1024**3:.2f}GB " | ||
| f"offload={os.environ.get('OFFLOAD','1')} autotp={os.environ.get('AUTOTP','2')} " | ||
| f"ws={os.environ.get('WORLD_SIZE','1')}", | ||
| flush=True, | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
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,49 @@ | ||
| """Isolated teacher test: AutoTP + ZeRO-3 (offload) forward_to_cache. | ||
|
|
||
| Env knobs: | ||
| TEACHER_MODEL (default local path), OFFLOAD (1/0), AUTOTP (int) | ||
| Launch: deepspeed --num_gpus N test_teacher_autotp_zero3.py | ||
| """ | ||
| import os | ||
| import sys | ||
|
|
||
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | ||
|
|
||
| import torch | ||
| import deepspeed | ||
| from deepspeed.accelerator import get_accelerator | ||
|
|
||
| from teacher import TeacherWrapper | ||
| from config import TeacherConfig | ||
|
|
||
| MODEL = os.environ.get("TEACHER_MODEL", "/root/autodl-tmp/models/Qwen2.5-1.5B-Instruct") | ||
|
tohtana marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def main(): | ||
| deepspeed.init_distributed() | ||
| cfg = TeacherConfig( | ||
| model_name_or_path=MODEL, | ||
| dtype="bfloat16", | ||
| offload_to_cpu=os.environ.get("OFFLOAD", "1") == "1", | ||
| autotp_size=int(os.environ.get("AUTOTP", "2")), | ||
| ) | ||
| ws = int(os.environ.get("WORLD_SIZE", 1)) | ||
| teacher = TeacherWrapper(cfg, world_size=ws) | ||
|
|
||
| dev = get_accelerator().current_device_name() | ||
| input_ids = torch.tensor([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]], device=dev) | ||
| attn = torch.ones_like(input_ids) | ||
| cache = teacher.forward_to_cache(input_ids, attn) | ||
|
|
||
| if deepspeed.comm.get_rank() == 0: | ||
| print( | ||
| f"TEACHER_OK shape={cache.shape} " | ||
| f"mem={torch.cuda.max_memory_allocated()/1024**3:.2f}GB " | ||
| f"offload={cfg.offload_to_cpu} autotp={cfg.autotp_size} ws={ws}", | ||
| flush=True, | ||
| ) | ||
| cache.free() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
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.