Torch-to-Linalg lowering fails to legalize torch.vtensor.literal for Hugging Face TinyLlama forward export
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 736
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 15
Description
Summary
I am trying to lower a Hugging Face transformer-style model through Torch-MLIR to LINALG_ON_TENSORS, but the lowering fails during the Torch backend IR → Linalg-on-tensors conversion with:
failed to legalize operation 'torch.vtensor.literal'
usr/lib/python3.12/copyreg.py:99: FutureWarning: `isinstance(treespec, LeafSpec)` is deprecated, use `isinstance(treespec, TreeSpec) and treespec.is_leaf()` instead.
return cls.__new__(cls, *args)
loc(callsite("/home/ubuntu/sa_mlir_full_stack/venv/lib/python3.12/site-packages/transformers/models/llama/modeling_llama.py":399:0 at callsite("/home/ubuntu/sa_mlir_full_stack/venv/lib/python3.12/site-packages/transformers/models/llama/modeling_llama.py":474:0 at "/home/ubuntu/models_mod_2/capture_frontend.py":80:0))): error: failed to legalize operation 'torch.vtensor.literal'
Traceback (most recent call last):
File "/home/ubuntu/models_mod_2/compile_to_hazard3.py", line 628, in <module>
main()
File "/home/ubuntu/models_mod_2/compile_to_hazard3.py", line 468, in main
mlir_module = export_and_import(
^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/sa_mlir_full_stack/venv/lib/python3.12/site-packages/torch_mlir/fx.py", line 147, in export_and_import
return _module_lowering(
^^^^^^^^^^^^^^^^^
File "/home/ubuntu/sa_mlir_full_stack/venv/lib/python3.12/site-packages/torch_mlir/fx.py", line 86, in _module_lowering
return lower_mlir_module(verbose, output_type, torch_mod, backend_options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/sa_mlir_full_stack/venv/lib/python3.12/site-packages/torch_mlir/compiler_utils.py", line 218, in lower_mlir_module
run_pipeline_with_repro_report(
File "/home/ubuntu/sa_mlir_full_stack/venv/lib/python3.12/site-packages/torch_mlir/compiler_utils.py", line 136, in run_pipeline_with_repro_report
raise TorchMlirCompilerError(trimmed_message) from None
torch_mlir.compiler_utils.TorchMlirCompilerError: Lowering Torch Backend IR -> Linalg-on-Tensors Backend IR failed with the following diagnostics:
python exception: Failure while executing pass pipeline
For Torch-MLIR developers, the error can be reproduced with:
$ torch-mlir-opt -pass-pipeline='builtin.module(torch-backend-to-linalg-on-tensors-backend-pipeline{allow-non-finites=True})' /tmp/UnnammedModule.mlir
Add '-mlir-print-ir-after-all -mlir-disable-threading' to get the IR dump for debugging purpose.
Please let me know if you need more context. @momchil-velikov
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the torch-backend-to-linalg-on-tensors-backend-pipeline command and inspect /tmp/UnnammedModule.mlir. Use -mlir-print-ir-after-all and -mlir-disable-threading as suggested, starting from the torch.vtensor.literal operation and the call sites in capture_frontend.py and modeling_llama.py. Done means the TinyLlama forward export passes this lowering pipeline without the legalization error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- huggingface, pytorch
- Domain
- compilers, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100