{"id":18335723,"url":"https://github.com/shadensmith/modelstepper","last_synced_at":"2025-10-19T15:21:32.881Z","repository":{"id":43228585,"uuid":"241598876","full_name":"ShadenSmith/ModelStepper","owner":"ShadenSmith","description":"Musings on debugging DeepSpeed codes.","archived":false,"fork":false,"pushed_at":"2023-10-03T21:42:55.000Z","size":13,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-01T19:51:31.904Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ShadenSmith.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-02-19T10:56:26.000Z","updated_at":"2020-10-28T01:53:56.000Z","dependencies_parsed_at":"2023-01-22T02:00:39.806Z","dependency_job_id":"8d94444a-0008-45eb-9951-de657b7a37ea","html_url":"https://github.com/ShadenSmith/ModelStepper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShadenSmith%2FModelStepper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShadenSmith%2FModelStepper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShadenSmith%2FModelStepper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShadenSmith%2FModelStepper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ShadenSmith","download_url":"https://codeload.github.com/ShadenSmith/ModelStepper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103732,"owners_count":21048235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T20:04:17.096Z","updated_at":"2025-10-19T15:21:32.828Z","avatar_url":"https://github.com/ShadenSmith.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ModelStepper\nA debugger for DeepSpeed engines. ModelStepper tracks model parameters, gradients, and\nloss with configurable tolerances.\n\nModelStepper accepts two training engines as returned from `deepspeed.initialize()` (one\nbaseline and one test) and a `DataLoader` for training. ModelStepper's `go()` method will\ntrain some number of batches and track the specified values (i.e., parameters, loss,\nand/or gradients). If a tracked component diverges from the baseline within a specified\ntolerance, `go()` returns `False` and reports information on the divergence.\n\n**Note:** the divergence of parameters and gradients is currently decided by the\n*relative* difference between the tensors, i.e., `((B - A).norm() / A.norm())`. The\nabsolute difference is still communicated when diverged.\n\nAssumptions:\n* The user must ensure that the baseline and tracked model are initialized with the same\n  state.\n* If parameters or gradients are tracked, the models are aligned such\n\t`base_eng.module.parameters()` are comparable `test_eng.module.parameters()`.\n\tIn the near future, we should support doing an `all_gather()` to coordinate\n\twith varying model parallelism.\n\n\n## Usage\nModelStepper has a small API:\n\n```python\nstepper = ModelStepper(base_engine,\n                       test_engine,\n                       trainloader,\n                       num_batches=50,\n                       test_every=1)\nsuccess = stepper.go()\n```\n\nCheck out [demo.py](demo.py) and [ModelStepper.py](ModelStepper.py) for more details.\n\n\n## Example\n\nTry the demo:\n```bash\n$ deepspeed demo.py --deepspeed --deepspeed_config=ds_config.json\n\n\u003csnip\u003e\n\n--- Model Stepper Configuration ---\nbatches=50\ntest_every=1\nstatus_every=5\ntrack_params=True\nparam_tol=1.000000e-05\ntrack_loss=True\nloss_tol=1.000000e-05\ntrack_grads=True\ngrad_tol=1.000000e-05\n\nSTATUS batch=0 / 50 base_loss=2.30138 test_loss=2.30138 abs_diff=0.00000e+00 rel_diff=0.00000e+00\nSTATUS batch=5 / 50 base_loss=2.29744 test_loss=2.29744 abs_diff=0.00000e+00 rel_diff=0.00000e+00\nSTATUS batch=10 / 50 base_loss=2.25951 test_loss=2.25951 abs_diff=0.00000e+00 rel_diff=0.00000e+00\nSTATUS batch=15 / 50 base_loss=2.19609 test_loss=2.19609 abs_diff=0.00000e+00 rel_diff=0.00000e+00\nSTATUS batch=20 / 50 base_loss=2.12497 test_loss=2.12497 abs_diff=0.00000e+00 rel_diff=0.00000e+00\nSTATUS batch=25 / 50 base_loss=2.05403 test_loss=2.05403 abs_diff=2.38419e-07 rel_diff=1.16074e-07\nSTATUS batch=30 / 50 base_loss=1.99819 test_loss=1.99819 abs_diff=1.19209e-07 rel_diff=5.96587e-08\nSTATUS batch=35 / 50 base_loss=1.97918 test_loss=1.97918 abs_diff=0.00000e+00 rel_diff=0.00000e+00\nSTATUS batch=40 / 50 base_loss=1.98365 test_loss=1.98365 abs_diff=0.00000e+00 rel_diff=0.00000e+00\nSTATUS batch=45 / 50 base_loss=1.85610 test_loss=1.85610 abs_diff=0.00000e+00 rel_diff=0.00000e+00\nSTATUS batch=49 / 50 base_loss=1.89003 test_loss=1.89003 abs_diff=0.00000e+00 rel_diff=0.00000e+00\nTEST PASSED\n```\n\nIn contrast, here is the result of the `--fail` flag to demo a test failure. This\nmode sets `lr=0` in the tested model:\n```bash\n$ deepspeed demo.py --deepspeed --deepspeed_config=ds_config.json --fail\n\n\u003csnip\u003e\n\nDIVERGED PARAMETER rank=2 batch=0 param_idx=0 abs_diff=2.11209e-02 rel_diff=1.47273e-02 tol=1.00000e-04\nDIVERGED PARAMETER rank=0 batch=0 param_idx=0 abs_diff=2.11209e-02 rel_diff=1.47273e-02 tol=1.00000e-04\nDIVERGED PARAMETER rank=3 batch=0 param_idx=0 abs_diff=2.11209e-02 rel_diff=1.47273e-02 tol=1.00000e-04\nDIVERGED PARAMETER rank=1 batch=0 param_idx=0 abs_diff=2.11209e-02 rel_diff=1.47273e-02 tol=1.00000e-04\nSTATUS batch=0 / 50 base_loss=2.30138 test_loss=2.30138 abs_diff=0.00000e+00 rel_diff=0.00000e+00\nTEST FAILED\n```\n\nModelStepper immediately detects that the model parameters have diverged from the\nbaseline.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshadensmith%2Fmodelstepper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshadensmith%2Fmodelstepper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshadensmith%2Fmodelstepper/lists"}