From ba2d3b1333b90ccd0186216649a1c58c6a17ce56 Mon Sep 17 00:00:00 2001 From: Driss Guessous <32754868+drisspg@users.noreply.github.com> Date: Thu, 29 Aug 2024 22:51:40 -0400 Subject: [PATCH] add in formatting skip everything (#779) ghstack-source-id: 34fe56595eac4d1a2fecb07a230307c0b2b767d7 Pull Request resolved: https://github.com/pytorch/ao/pull/688 --- .github/workflows/ruff_linter.yml | 30 ++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 20 ++++++++++++++++++++ dev-requirements.txt | 4 ++++ ruff.toml | 8 ++++++++ torchao/float8/inference.py | 6 ++---- 5 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/ruff_linter.yml create mode 100644 .pre-commit-config.yaml create mode 100644 ruff.toml diff --git a/.github/workflows/ruff_linter.yml b/.github/workflows/ruff_linter.yml new file mode 100644 index 000000000..fe0831070 --- /dev/null +++ b/.github/workflows/ruff_linter.yml @@ -0,0 +1,30 @@ +name: Code Analysis with Ruff + +on: + push: + branches: + - main + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9"] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ruff + - name: Analyzing the code with ruff + run: | + ruff check . + - name: Check well formatted code + run: | + ruff format --check diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..48a5d301b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.5.6 + hooks: + # Run the linter. + - id: ruff + args: [--fix] + # Run the formatter. + - id: ruff-format diff --git a/dev-requirements.txt b/dev-requirements.txt index a400b1c1e..6fdcb0aca 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -17,3 +17,7 @@ tabulate # QOL for printing tables to stdout # Custom CUDA Extensions ninja + +# Linting +ruff +pre-commit diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 000000000..0c35ab4f5 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,8 @@ +# Currently, we ignore all files in the project by default. +# We plan to add files in chunks using the 'include' list below. +# To add a new path: Simply add it to the 'include' list. +# Example: To lint all files in every subfolder of 'test', add "test/**/*" +include = [ + "torchao/float8/inference.py", + "torchao/float8/float8_utils.py", +] diff --git a/torchao/float8/inference.py b/torchao/float8/inference.py index b3d5de144..e25c73ce4 100644 --- a/torchao/float8/inference.py +++ b/torchao/float8/inference.py @@ -10,11 +10,12 @@ from dataclasses import dataclass from enum import auto, Enum -from typing import Callable, List, Optional, Tuple +from typing import Callable, Optional, Tuple import torch import torch.nn as nn from torchao.float8.float8_linear_utils import swap_linear_layers +from torchao.float8.float8_utils import is_row_major, pad_tensor_for_matmul from torchao.float8.float8_tensor import ( Float8Tensor, @@ -244,9 +245,6 @@ def quantize_to_float8( ) -from torchao.float8.float8_utils import is_row_major, pad_tensor_for_matmul - - def preprocess_data( a_data: torch.Tensor, b_data: torch.Tensor, scaled_mm_config: ScaledMMConfig ) -> Tuple[torch.Tensor, torch.Tensor]: