Download scale/script/test_launch_sml_1m.py from Tinghong-Ye22/code-Movens-Zero_train: direct link, hf CLI and curl.
- Browser
- Download file 5 kB
-
https://huggingface.co/Tinghong-Ye22/code-Movens-Zero_train/resolve/main/scale/script/test_launch_sml_1m.py
- Command line
-
hf download hf://Tinghong-Ye22/code-Movens-Zero_train/scale/script/test_launch_sml_1m.py
-
curl -L -o test_launch_sml_1m.py https://huggingface.co/Tinghong-Ye22/code-Movens-Zero_train/resolve/main/scale/script/test_launch_sml_1m.py
5 kB
| import importlib.util | |
| import json | |
| import os | |
| from pathlib import Path | |
| import sys | |
| import tempfile | |
| import unittest | |
| from unittest.mock import patch | |
| spec = importlib.util.spec_from_file_location("sml_launcher", Path(__file__).with_name("launch_sml_1m.py")) | |
| launch = importlib.util.module_from_spec(spec) | |
| spec.loader.exec_module(launch) | |
| class LauncherTests(unittest.TestCase): | |
| def test_layout_and_budget(self): | |
| self.assertEqual([s["gpus"] for s in launch.LAYOUT.values()], [[0, 1], [2, 3], [4, 5, 6, 7]]) | |
| self.assertEqual(len({s["port"] for s in launch.LAYOUT.values()}), 3) | |
| for s, spec in launch.LAYOUT.items(): | |
| cmd = launch.command(s) | |
| self.assertEqual(cmd[cmd.index("--max-steps")+1], "1000000") | |
| self.assertEqual(cmd[cmd.index("--global-batch")+1], "48") | |
| self.assertEqual(48 // len(spec["gpus"]), 12 if s == "L" else 24) | |
| self.assertIn(str(launch.GROUP), cmd) | |
| self.assertNotIn("--resume", cmd) | |
| self.assertEqual(float(cmd[cmd.index("--effective-motion-lr")+1]), 1e-4) | |
| self.assertEqual(float(cmd[cmd.index("--effective-omni-lr")+1]), 1e-5) | |
| self.assertIn("--disable-jerk-loss", cmd) | |
| self.assertEqual(launch.GROUP.name, "sml_1m_224_a1e-4_o1e-5_nojerk") | |
| def test_actual_learning_rates_are_guarded(self): | |
| with tempfile.TemporaryDirectory() as d, patch.object(launch, "GROUP", Path(d)): | |
| config = dict(world_size_expected=2, initial_action_checkpoint=None, warmstart_checkpoint=None, | |
| train=dict(max_training_steps=1000000, train_batch_size=24, | |
| gradient_accumulation_steps=1, output_dir=d, learning_rate=1e-3), | |
| model=dict(lang_backbone_lr=1e-4), absolute_height_stage=dict(lr_scale=0.1)) | |
| config["train"].update({key: 0.0 for key in launch.JERK_WEIGHT_FIELDS}) | |
| path = Path(d) / "config.json" | |
| path.write_text(json.dumps(config)) | |
| launch.verify_group_config("S", path) | |
| # Setting only the base LR to 1e-4 would silently yield 1e-5: reject it. | |
| config["train"]["learning_rate"] = 1e-4 | |
| path.write_text(json.dumps(config)) | |
| with self.assertRaisesRegex(ValueError, "effective action LR"): | |
| launch.verify_group_config("S", path) | |
| config["train"]["learning_rate"] = 1e-3 | |
| config["model"]["lang_backbone_lr"] = 1e-5 | |
| path.write_text(json.dumps(config)) | |
| with self.assertRaisesRegex(ValueError, "Omni LR"): | |
| launch.verify_group_config("S", path) | |
| config["model"]["lang_backbone_lr"] = 1e-4 | |
| for key in launch.JERK_WEIGHT_FIELDS: | |
| config["train"][key] = 0.1 | |
| path.write_text(json.dumps(config)) | |
| with self.assertRaisesRegex(ValueError, "jerk loss coefficient"): | |
| launch.verify_group_config("S", path) | |
| config["train"][key] = 0.0 | |
| def test_env_has_no_inherited_distributed_job(self): | |
| with tempfile.TemporaryDirectory() as d, patch.object(launch, "GROUP", Path(d)), patch.dict(os.environ, {"WORLD_SIZE": "8", "RANK": "7", "MASTER_PORT": "1", "PET_NNODES": "4"}): | |
| env = launch.child_env("M") | |
| self.assertEqual(env["CUDA_VISIBLE_DEVICES"], "2,3") | |
| self.assertTrue(env["WANDB_DIR"].startswith(d)) | |
| self.assertTrue(env["TMPDIR"].startswith("/tmp/")) | |
| for k in ["WORLD_SIZE", "RANK", "MASTER_PORT", "PET_NNODES"]: | |
| self.assertNotIn(k, env) | |
| def test_gpu_guard_never_accepts_four_gpu_dsw(self): | |
| four = "\n".join(f"{i}, GPU-{i}, 0" for i in range(4)) | |
| with patch.object(launch.subprocess, "check_output", return_value=four): | |
| with self.assertRaisesRegex(RuntimeError, "exactly eight"): | |
| launch.require_idle_eight_gpus() | |
| eight = "\n".join(f"{i}, GPU-{i}, 0" for i in range(8)) | |
| with patch.object(launch.subprocess, "check_output", side_effect=[eight, "GPU-3, 123"]): | |
| with self.assertRaisesRegex(RuntimeError, "already occupied"): | |
| launch.require_idle_eight_gpus() | |
| def test_failure_stops_only_spawned_siblings(self): | |
| with tempfile.TemporaryDirectory() as d: | |
| status = Path(d) / "status.json" | |
| specs = [("S", [sys.executable, "-c", "raise SystemExit(3)"], os.environ.copy()), | |
| ("M", [sys.executable, "-c", "import time; time.sleep(60)"], os.environ.copy())] | |
| with self.assertRaisesRegex(RuntimeError, "member failed"): | |
| launch.supervise(specs, status) | |
| result = json.loads(status.read_text()) | |
| self.assertEqual(result["jobs"]["S"]["exit_code"], 3) | |
| self.assertIsNotNone(result["jobs"]["M"]["exit_code"]) | |
| self.assertEqual(result["state"], "failed_or_interrupted") | |
| if __name__ == "__main__": | |
| unittest.main() | |