|
| 1 | +"""End-to-end CI smoke: compile an example, generate, check the output. |
| 2 | +
|
| 3 | +Compiles ``examples/binary_increment.py`` to a Hugging Face bundle and |
| 4 | +verifies that a ``transformers`` pipeline loaded from it increments a |
| 5 | +binary string. This exercises the full stack — graph construction, |
| 6 | +scheduling, weight writing, bundle export, tokenizer, generation — |
| 7 | +in about a minute on a CPU runner, standing in for the full suite on |
| 8 | +every push (the full suite runs on Modal locally and on the weekly |
| 9 | +full-tests workflow). |
| 10 | +""" |
| 11 | + |
| 12 | +import sys |
| 13 | +import tempfile |
| 14 | +from pathlib import Path |
| 15 | + |
| 16 | + |
| 17 | +def main() -> int: |
| 18 | + from examples.binary_increment import D_HEAD, D_MODEL, create_network_parts |
| 19 | + from torchwright import compile_hf_bundle |
| 20 | + |
| 21 | + output_node, embedding = create_network_parts() |
| 22 | + with tempfile.TemporaryDirectory() as tmp: |
| 23 | + bundle = Path(tmp) / "binary_increment_hf_bundle" |
| 24 | + compile_hf_bundle(output_node, embedding, str(bundle), d=D_MODEL, d_head=D_HEAD) |
| 25 | + |
| 26 | + from transformers import pipeline |
| 27 | + |
| 28 | + generate = pipeline("text-generation", model=str(bundle)) |
| 29 | + out = generate("1011\n", return_full_text=False)[0]["generated_text"] |
| 30 | + |
| 31 | + print(f"generated: {out!r}") |
| 32 | + if out.strip() != "1100": |
| 33 | + print("FAIL: expected '1100'", file=sys.stderr) |
| 34 | + return 1 |
| 35 | + print("smoke OK") |
| 36 | + return 0 |
| 37 | + |
| 38 | + |
| 39 | +if __name__ == "__main__": |
| 40 | + sys.exit(main()) |
0 commit comments