()
| 4 | import os |
| 5 | |
| 6 | def test_bert_inference(): |
| 7 | with torch.no_grad(): |
| 8 | model, args = BertModel.from_pretrained('bert-base-uncased') |
| 9 | model = model.to(int(os.getenv('LOCAL_RANK'))) |
| 10 | model_device = next(model.parameters()).device |
| 11 | x = torch.ones((8, 256), device=model_device, dtype=torch.long) |
| 12 | inp = x.clone(); inp[:, -10:]*=30000 # split vocab |
| 13 | a = model(input_ids=inp, position_ids=x, attention_mask=None, token_type_ids=x*0) |
| 14 | mp_split_model(model, 2) |
| 15 | |
| 16 | b = model(input_ids=inp, position_ids=x, attention_mask=None, token_type_ids=x*0) |
| 17 | |
| 18 | print((a[0]-b[0]).abs().max()) |
| 19 | # assert torch.allclose(a[0], b[0]) |
| 20 | |
| 21 | if __name__ == '__main__': |
| 22 | # torchrun --standalone --nnodes=1 --nproc-per-node=2 tests/test_model_parallel.py |
no test coverage detected