Skip to content

Add ruff and isort #578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 24, 2025
Merged

Add ruff and isort #578

merged 8 commits into from
Jul 24, 2025

Conversation

XuehaoSun
Copy link
Contributor

@XuehaoSun XuehaoSun commented May 28, 2025

Add ruff and isort

XuehaoSun added 2 commits May 28, 2025 00:14
Signed-off-by: Sun, Xuehao <xuehao.sun@intel.com>
@XuehaoSun XuehaoSun force-pushed the xuehao/pre-commit branch from 6d45ee0 to 47a8063 Compare July 24, 2025 01:25
@XuehaoSun XuehaoSun marked this pull request as ready for review July 24, 2025 02:06
@wenhuach21 wenhuach21 requested review from Copilot and wenhuach21 July 24, 2025 07:45
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds ruff and isort as code linting and formatting tools to the project. The changes introduce comprehensive code style enforcement through configuration files and pre-commit hooks, while making extensive formatting changes throughout the codebase to conform to the new standards.

  • Adds ruff and isort configuration in pyproject.toml with specific linting rules and import sorting settings
  • Updates pre-commit configuration to include new linting and formatting hooks
  • Applies extensive import reordering and code formatting across the entire codebase to meet new standards

Reviewed Changes

Copilot reviewed 96 out of 97 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
pyproject.toml Added comprehensive ruff and isort configuration settings
.pre-commit-config.yaml Added pre-commit hooks for ruff and isort, plus additional code quality checks
test//test_.py Reordered imports and applied formatting fixes across all test files
auto_round/*.py Applied import sorting and formatting changes to core library files
auto_round_extension/*.py Added copyright headers and formatting fixes to extension modules
setup.py Minor import reordering and code style improvements

Comment on lines +51 to +79
assert is_pure_text_model(model)

def test_Qwen(self):
model_name = "/models/Qwen2.5-7B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [28])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_phi4(self):
model_name = "/models/phi-4"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [40])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_llama3(self):
model_name = "/models/Meta-Llama-3.1-8B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [32])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_mixtral(self):
model_name = "/models/Mixtral-8x7B-Instruct-v0.1"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [32])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of bare assert statement without descriptive message. Consider adding a descriptive message for better debugging: assert is_pure_text_model(model), "Expected model to be pure text model"

Copilot uses AI. Check for mistakes.

Comment on lines +51 to +93
assert is_pure_text_model(model)

def test_Qwen(self):
model_name = "/models/Qwen2.5-7B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [28])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_phi4(self):
model_name = "/models/phi-4"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [40])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_llama3(self):
model_name = "/models/Meta-Llama-3.1-8B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [32])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_mixtral(self):
model_name = "/models/Mixtral-8x7B-Instruct-v0.1"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [32])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_falcon(self):
model_name = "/models/Falcon3-7B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [28])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_orca(self):
model_name = "/models/Orca-2-7b"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [32])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of bare assert statement without descriptive message. Consider adding a descriptive message for better debugging: assert is_pure_text_model(model), "Expected model to be pure text model"

Copilot uses AI. Check for mistakes.

Comment on lines +51 to +100
assert is_pure_text_model(model)

def test_Qwen(self):
model_name = "/models/Qwen2.5-7B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [28])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_phi4(self):
model_name = "/models/phi-4"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [40])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_llama3(self):
model_name = "/models/Meta-Llama-3.1-8B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [32])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_mixtral(self):
model_name = "/models/Mixtral-8x7B-Instruct-v0.1"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [32])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_falcon(self):
model_name = "/models/Falcon3-7B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [28])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_orca(self):
model_name = "/models/Orca-2-7b"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [32])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_OLMo(self):
model_name = "/models/OLMo-2-1124-7B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [32])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of bare assert statement without descriptive message. Consider adding a descriptive message for better debugging: assert is_pure_text_model(model), "Expected model to be pure text model"

Copilot uses AI. Check for mistakes.

Comment on lines +51 to +100
assert is_pure_text_model(model)

def test_Qwen(self):
model_name = "/models/Qwen2.5-7B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [28])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_phi4(self):
model_name = "/models/phi-4"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [40])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_llama3(self):
model_name = "/models/Meta-Llama-3.1-8B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [32])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_mixtral(self):
model_name = "/models/Mixtral-8x7B-Instruct-v0.1"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [32])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_falcon(self):
model_name = "/models/Falcon3-7B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [28])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_orca(self):
model_name = "/models/Orca-2-7b"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [32])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)

def test_OLMo(self):
model_name = "/models/OLMo-2-1124-7B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", trust_remote_code=True)
block_names = get_block_names(model)
self.check_block_names(block_names, ["model.layers"], [32])
assert is_pure_text_model(model) == True
assert is_pure_text_model(model)
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of bare assert statement without descriptive message. Consider adding a descriptive message for better debugging: assert is_pure_text_model(model), "Expected model to be pure text model"

Copilot uses AI. Check for mistakes.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@wenhuach21 wenhuach21 merged commit 774a5ae into main Jul 24, 2025
2 of 6 checks passed
@wenhuach21 wenhuach21 deleted the xuehao/pre-commit branch July 24, 2025 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants