Release experimental Transition Foundation Model v0.1 with reproducible source and validation
1baf215 verified Download tests/test_export.py from maxffarrell/transition-foundation-model: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/maxffarrell/transition-foundation-model/resolve/main/tests/test_export.py
- Command line
-
hf download hf://maxffarrell/transition-foundation-model/tests/test_export.py
-
curl -L -o test_export.py https://huggingface.co/maxffarrell/transition-foundation-model/resolve/main/tests/test_export.py
1.47 kB
| import hashlib | |
| import json | |
| import pytest | |
| import torch | |
| from tfm.data import Normalization, generate_dataset, load_manifest_episodes | |
| from tfm.models import build_model | |
| def test_export_dynamic_batch_queries_and_preprocessing_bundle(tmp_path): | |
| pytest.importorskip("onnx") | |
| pytest.importorskip("onnxruntime") | |
| from tfm.export.onnx import export_model | |
| data = tmp_path / "data" | |
| generate_dataset(data, systems=9, days=0.5, seed=3) | |
| normalization = Normalization.fit(load_manifest_episodes(data, split="train")) | |
| run = tmp_path / "run" | |
| run.mkdir() | |
| normalization.save(run / "normalization.json") | |
| model = build_model("transformer", {"d_model": 16, "ff_dim": 32, "heads": 4, "layers": 1}) | |
| torch.save( | |
| { | |
| "model_kind": "transformer", | |
| "model_config": model.config, | |
| "model_state": model.state_dict(), | |
| "normalization_sha256": hashlib.sha256((run / "normalization.json").read_bytes()).hexdigest(), | |
| }, | |
| run / "checkpoint.pt", | |
| ) | |
| output = tmp_path / "onnx" | |
| result = export_model(run / "checkpoint.pt", data, output) | |
| assert result["onnxruntime_verified"] | |
| assert result["dynamic_axes"] == ["batch", "queries"] | |
| assert result["fixed_shapes"]["query_fields"] == [None] | |
| assert (output / "normalization.json").read_bytes() == (run / "normalization.json").read_bytes() | |
| assert json.loads((output / "schema.json").read_text())["version"] == "tfm-schema-v1" | |