()
| 376 | |
| 377 | |
| 378 | def test_state_dict(): |
| 379 | data_shape = (2, 28) |
| 380 | data = tensor(np.random.random(data_shape)) |
| 381 | mlp = MLP() |
| 382 | pred0 = mlp(data) |
| 383 | |
| 384 | with BytesIO() as fout: |
| 385 | mge.save(mlp.state_dict(), fout) |
| 386 | fout.seek(0) |
| 387 | state_dict = mge.load(fout) |
| 388 | state_dict["extra"] = None |
| 389 | mlp1 = MLP() |
| 390 | mlp1.load_state_dict(state_dict, strict=False) |
| 391 | pred1 = mlp1(data) |
| 392 | np.testing.assert_allclose(pred0.numpy(), pred1.numpy(), atol=5e-6) |
| 393 | with pytest.raises(KeyError): |
| 394 | mlp1.load_state_dict(state_dict) |
| 395 | del state_dict["extra"] |
| 396 | del state_dict["dense0.bias"] |
| 397 | with pytest.raises(KeyError): |
| 398 | mlp1.load_state_dict(state_dict) |
| 399 | |
| 400 | |
| 401 | def test_format_after_load_state_dict(): |
nothing calls this directly
no test coverage detected