test_compilation.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import glob
  2. import os
  3. import runpy
  4. import tempfile
  5. import depyf
  6. temp_dir = tempfile.mkdtemp()
  7. with depyf.prepare_debug(temp_dir):
  8. cur_dir = os.path.dirname(__file__)
  9. parent_dir = os.path.dirname(cur_dir)
  10. root_dir = os.path.dirname(parent_dir)
  11. example_file = os.path.join(root_dir, "examples",
  12. "offline_inference",
  13. "tpu_inference.py")
  14. runpy.run_path(example_file)
  15. compiled_code = sorted(
  16. glob.glob(os.path.join(temp_dir, "__transformed_code*.py")))
  17. full_code = glob.glob(os.path.join(temp_dir, "full_code*.py"))[0]
  18. # we should only trigger Dynamo compilation three times:
  19. # one for the profiling phase (and the compiled artifact will be discarded)
  20. # one for the prefill phase with symbolic shapes
  21. # one for the decode phase with symbolic shapes
  22. # and later calls should not trigger Dynamo compilation again.
  23. # NOTE: it might still trigger XLA compilation.
  24. # check we have three compiled code
  25. assert len(compiled_code) == 3
  26. # check the first compilation is discarded
  27. with open(full_code) as f:
  28. full_code_content = f.read()
  29. profile_function = compiled_code[0].split(".")[0]
  30. assert profile_function not in full_code_content