(model, config_dict, hidden_dim, dtype, requires_grad)
| 274 | |
| 275 | |
| 276 | def run_model(model, config_dict, hidden_dim, dtype, requires_grad): |
| 277 | model, _, _, _ = deepspeed.initialize(model=model, model_parameters=model.parameters(), config=config_dict) |
| 278 | data_loader = random_dataloader(model=model, |
| 279 | total_samples=10, |
| 280 | hidden_dim=hidden_dim, |
| 281 | device=model.device, |
| 282 | dtype=dtype) |
| 283 | dist.barrier() |
| 284 | for batch in data_loader: |
| 285 | batch[0].requires_grad = requires_grad |
| 286 | loss = model(batch[0], batch[1]) |
| 287 | loss = loss[1] |
| 288 | model.backward(loss) |
| 289 | model.step() |
| 290 | |
| 291 | # Needed in ZeRO 3. Not doing so can give memory leak |
| 292 | model.destroy() |
| 293 | |
| 294 | |
| 295 | class TestSetZ3LeafModule(DistributedTest): |
no test coverage detected