Download tests/test_checkpoint_marker_atomicity.py from Tinghong-Ye22/code-HFD: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/tests/test_checkpoint_marker_atomicity.py
- Command line
-
hf download hf://Tinghong-Ye22/code-HFD/tests/test_checkpoint_marker_atomicity.py
-
curl -L -o test_checkpoint_marker_atomicity.py https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/tests/test_checkpoint_marker_atomicity.py
1.47 kB
| from types import SimpleNamespace | |
| import pytest | |
| from psi.trainers import posttrain_full_duplex as module | |
| def test_invalid_contract_does_not_truncate_existing_marker(tmp_path, monkeypatch): | |
| marker = tmp_path / 'full_duplex_source_boundary.json' | |
| marker.write_text('{"previous": "valid"}') | |
| trainer = module.PosttrainFullDuplexTrainer.__new__(module.PosttrainFullDuplexTrainer) | |
| trainer.accelerator = SimpleNamespace(is_main_process=True) | |
| def invalid(): | |
| raise RuntimeError('missing production marker') | |
| monkeypatch.setattr(module, '_active_continuous_data_contract_identity', invalid) | |
| with pytest.raises(RuntimeError, match='missing production marker'): | |
| trainer._write_full_duplex_boundary_marker(str(tmp_path), global_step=10) | |
| assert marker.read_text() == '{"previous": "valid"}' | |
| assert not (tmp_path / 'full_duplex_source_boundary.json.partial').exists() | |
| def test_invalid_contract_fails_before_saving_state(monkeypatch): | |
| trainer = module.PosttrainFullDuplexTrainer.__new__(module.PosttrainFullDuplexTrainer) | |
| trainer._at_source_group_boundary = True | |
| def invalid(): | |
| raise RuntimeError('missing production marker') | |
| monkeypatch.setattr(module, '_active_continuous_data_contract_identity', invalid) | |
| # No accelerator/model is provided: touching save_state would fail this test. | |
| with pytest.raises(RuntimeError, match='missing production marker'): | |
| trainer.save_checkpoint(10) | |