Switch to pre-commit for lint checks. (#3200)

Users can run via `pre-commit run` or set up a hook as described in the
instructions: https://pre-commit.com/

The CI is set to only run pre-commit on files changed in the patch. We
will run with `--all-files` in a separate patch.
pull/3244/head
Stella Laurenzo 2024-04-27 13:29:51 -07:00 committed by GitHub
parent 189b3f112f
commit fb8748bdfa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 64 additions and 32 deletions

View File

@ -1,26 +0,0 @@
# yamllint disable rule:line-length
name: Lint Checks
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
static_lint_checks:
name: Static Lint Checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# `git-clang-format` needs access to the commit before the
# current merge commit to know what changes to format.
fetch-depth: 2
- name: Validate GitHub Actions yaml files
run: |
yamllint ./.github/workflows/ ./.github/actions/
- name: Check clang-format
run: |
wget -q https://raw.githubusercontent.com/llvm/llvm-project/main/clang/tools/clang-format/git-clang-format
python3 git-clang-format --diff HEAD~1

View File

@ -0,0 +1,19 @@
name: pre-commit
on:
pull_request:
push:
branches: [main]
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# requites to grab the history of the PR
fetch-depth: 0
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.1
with:
extra_args: --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}

View File

@ -0,0 +1,21 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: "GeneratedTorchOps\\.td|abstract_interp_lib_gen\\.py|\\.excalidraw"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-ast
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: 'v18.1.4'
hooks:
- id: clang-format

View File

@ -1,2 +0,0 @@
[style]
based_on_style = pep8

View File

@ -1,4 +1,4 @@
# The Torch-MLIR Project # The Torch-MLIR Project
The Torch-MLIR project aims to provide first class compiler support from the [PyTorch](https://pytorch.org) ecosystem to the MLIR ecosystem. The Torch-MLIR project aims to provide first class compiler support from the [PyTorch](https://pytorch.org) ecosystem to the MLIR ecosystem.
@ -8,7 +8,7 @@ necessarily a reflection of the completeness or stability of the code, it
does indicate that the project is not yet endorsed as a component of LLVM. does indicate that the project is not yet endorsed as a component of LLVM.
[PyTorch](https://pytorch.org) [PyTorch](https://pytorch.org)
PyTorch is an open source machine learning framework that facilitates the seamless transition from research and prototyping to production-level deployment. PyTorch is an open source machine learning framework that facilitates the seamless transition from research and prototyping to production-level deployment.
[MLIR](https://mlir.llvm.org) [MLIR](https://mlir.llvm.org)
The MLIR project offers a novel approach for building extensible and reusable compiler architectures, which address the issue of software fragmentation, reduce the cost of developing domain-specific compilers, improve compilation for heterogeneous hardware, and promote compatibility between existing compilers. The MLIR project offers a novel approach for building extensible and reusable compiler architectures, which address the issue of software fragmentation, reduce the cost of developing domain-specific compilers, improve compilation for heterogeneous hardware, and promote compatibility between existing compilers.
@ -16,7 +16,7 @@ The MLIR project offers a novel approach for building extensible and reusable co
[Torch-MLIR](https://github.com/llvm/torch-mlir) [Torch-MLIR](https://github.com/llvm/torch-mlir)
Several vendors have adopted MLIR as the middle layer in their systems, enabling them to map frameworks such as PyTorch, JAX, and TensorFlow into MLIR and subsequently lower them to their target hardware. We have observed half a dozen custom lowerings from PyTorch to MLIR, making it easier for hardware vendors to focus on their unique value, rather than needing to implement yet another PyTorch frontend for MLIR. The ultimate aim is to be similar to the current hardware vendors adding LLVM target support, rather than each one implementing Clang or a C++ frontend. Several vendors have adopted MLIR as the middle layer in their systems, enabling them to map frameworks such as PyTorch, JAX, and TensorFlow into MLIR and subsequently lower them to their target hardware. We have observed half a dozen custom lowerings from PyTorch to MLIR, making it easier for hardware vendors to focus on their unique value, rather than needing to implement yet another PyTorch frontend for MLIR. The ultimate aim is to be similar to the current hardware vendors adding LLVM target support, rather than each one implementing Clang or a C++ frontend.
[![Release Build](https://github.com/llvm/torch-mlir/actions/workflows/buildRelease.yml/badge.svg)](https://github.com/llvm/torch-mlir/actions/workflows/buildRelease.yml) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
## All the roads from PyTorch to Torch MLIR Dialect ## All the roads from PyTorch to Torch MLIR Dialect
@ -76,7 +76,7 @@ pip install torch-mlir -f https://github.com/llvm/torch-mlir-release/releases/ex
## Demos ## Demos
### TorchScript ResNet18 ### TorchScript ResNet18
Standalone script to Convert a PyTorch ResNet18 model to MLIR and run it on the CPU Backend: Standalone script to Convert a PyTorch ResNet18 model to MLIR and run it on the CPU Backend:

View File

@ -26,6 +26,19 @@ python -m pip install -r requirements.txt
python -m pip install -r torchvision-requirements.txt python -m pip install -r torchvision-requirements.txt
``` ```
## (Optional) Set up pre-commit
This project uses [pre-commit](https://pre-commit.com/) in its CI. You can
install it locally too in order to lint and fix your code prior to the CI
complaining about it.
```shell
pip install pre-commit
# You can run interactively with `pre-commit run`
# or install hooks so it runs automatically:
pre-commit install
```
## CMake Build ## CMake Build
Two setups are possible to build: in-tree and out-of-tree. The in-tree setup is the most straightforward, as it will build LLVM dependencies as well. Two setups are possible to build: in-tree and out-of-tree. The in-tree setup is the most straightforward, as it will build LLVM dependencies as well.

7
pyproject.toml 100644
View File

@ -0,0 +1,7 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
[tool.black]
line-length = 88
target-version = ['py38']