Add MLIR integration with sub-byte data types for mixed-precision quantization#29
Conversation
Co-authored-by: Jzjerry <20167827+Jzjerry@users.noreply.github.com>
Co-authored-by: Jzjerry <20167827+Jzjerry@users.noreply.github.com>
|
@copilot Current MLIR generator seems to be working well, but less formatted. Can we utilize https://github.com/llvm/torch-mlir directly? Maybe we don't have to write all the codegen ourselves. |
Good point! I looked into torch-mlir and here's the trade-off: torch-mlir advantages:
Why current custom approach:
Possible hybrid approach: Should I explore adding torch-mlir integration as an optional backend? We could keep the current standalone generator as default and add torch-mlir-based generation as an alternative path. |
|
@copilot How about checking the https://github.com/HKUSTGZ-MICS-LYU/MiCo-Lib to see how far we can go? |
I checked MiCo-Lib and here's the integration path: Current flow (MiCoCodeGen): MLIR integration opportunity: The MLIR operations in
MiCo-Lib's packed types ( Next steps to consider:
This would give us MLIR as the optimization layer while reusing MiCo-Lib's hand-tuned kernels. Want me to prototype this lowering path? |
|
@copilot Great! I still want to share the torch-mlir as one of the first passes to do. In our dialect, we can create those low-bitwidth integer datatypes, or tensor datatypes. |
|
@copilot Now, let's start going? Create a mlir codegen with torch-mlir as a pass. |
Co-authored-by: Jzjerry <20167827+Jzjerry@users.noreply.github.com>
Created Usage: from MiCoTorchMLIRGen import MiCoTorchMLIRGen
mlir_gen = MiCoTorchMLIRGen(model, output_type="torch")
mlir_gen.forward(torch.randn(1, 1, 28, 28))
mlir_gen.convert("output", "lenet_torch_mlir")Features:
Install torch-mlir: pip install torch-mlir -f https://github.com/llvm/torch-mlir-release/releasesSee |
doc/MLIR_INTEGRATION.md)MiCoMLIRGen.py- New MLIR code generator moduleexamples/mlir_example.py)tests/test_mlir_codegen.py)MiCoTorchMLIRGen.py)Summary
This PR adds MLIR (Multi-Level Intermediate Representation) integration to the MiCo framework with two backends:
Backend 1: Standalone MiCoMLIRGen
!mico.int<N>for N ∈ {1,2,4,8})mico.bitlinear,mico.bitconv2d, etc.)Backend 2: MiCoTorchMLIRGen (NEW)
torch,linalg,stablehloFiles Added/Modified
MiCoMLIRGen.py: Standalone MLIR code generatorMiCoTorchMLIRGen.py: Torch-mlir based MLIR generator (NEW)doc/MLIR_INTEGRATION.md: Comprehensive proposal and dialect specificationexamples/mlir_example.py: Standalone MLIR examplesexamples/torch_mlir_example.py: Torch-mlir backend examples (NEW)tests/test_mlir_codegen.py: 19 unit tests for standalone generatortests/test_torch_mlir_codegen.py: 10 unit tests for torch-mlir generator (NEW)requirements.txt: Added torch-mlir as optional dependencyreadme.md: Updated with both backendsOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.