Skip to content

Commit b1432a1

Browse files
Merge pull request #4 from InfiniTensor/test_branch
Add code check
2 parents 7f7d5fe + e3e4190 commit b1432a1

22 files changed

Lines changed: 438 additions & 128 deletions

.flake8

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[flake8]
2+
# Python version target
3+
python-version = 3.10
4+
5+
# Maximum line length (matches black's default, but we allow longer for URLs/paths)
6+
max-line-length = 127
7+
8+
# Select only critical errors that would cause runtime issues
9+
# E9: Runtime errors (e.g., IndentationError, SyntaxError)
10+
# F63: Placeholder for assertions in pytests
11+
# F7: Various errors (e.g., two starred expressions in assignment)
12+
# F82: Undefined names
13+
select = E9,F63,F7,F82
14+
15+
# Ignore specific error codes
16+
# E203: Whitespace before ':' (conflicts with black)
17+
# W503: Line break before binary operator (conflicts with black)
18+
extend-ignore = E203,W503
19+
20+
# Directories to exclude from linting
21+
exclude =
22+
.git,
23+
__pycache__,
24+
.venv,
25+
venv,
26+
build,
27+
dist,
28+
*.egg-info
29+
30+
# Show source code for each error
31+
show-source = true
32+
33+
# Show statistics (number of each type of error)
34+
statistics = true

.github/workflows/ci.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Python Code Style Check
2+
3+
# Trigger on push to main/master branches or pull requests targeting them
4+
on:
5+
push:
6+
branches: [ "main", "master" ]
7+
pull_request:
8+
branches: [ "main", "master" ]
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
style_check:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: ["3.10"] # We can add more versions here, e.g., ["3.8", "3.10"]
19+
20+
steps:
21+
# 1. Checkout code
22+
- uses: actions/checkout@v4
23+
24+
# 2. Set up Python environment
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
cache: 'pip' # Enable pip caching to speed up future builds
30+
31+
# 3. Install dependencies
32+
- name: Install dependencies
33+
run: |
34+
python -m pip install --upgrade pip
35+
# Install linting and formatting tools
36+
pip install flake8 black==23.9.1
37+
38+
# Install project dependencies (if requirements.txt exists)
39+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
40+
41+
# 4. Linting with flake8
42+
- name: Lint with flake8
43+
run: |
44+
# stop the build if there are Python syntax errors or undefined names
45+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
46+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
47+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
48+
49+
# 5. Check formatting with Black
50+
- name: Check formatting with Black
51+
run: |
52+
# --check only verifies formatting without modifying files.
53+
# The CI will fail if the code is not formatted correctly.
54+
black . --check --verbose

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 23.9.1
4+
hooks:
5+
- id: black
6+
# Use pyproject.toml for configuration (ensures consistency)
7+
args: ['--config', 'pyproject.toml']
8+
- repo: https://github.com/pycqa/flake8
9+
rev: 6.1.0
10+
hooks:
11+
- id: flake8
12+
# Use .flake8 for configuration (separate file to avoid TOML parsing issues)
13+
# --exit-zero: show warnings but don't fail pre-commit
14+
args: ['--config', '.flake8', '--exit-zero']

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# InfiniMetrics
2-
31
<div align="center">
42

3+
# InfiniMetrics
4+
55
**An InfiniTensor-Featured Comprehensive Accelerator Evaluation Framework**
66

77
[![Format Check](https://img.shields.io/badge/Format_Check-passing-success)](https://github.com/InfiniTensor/InfiniMetrics)
@@ -42,6 +42,7 @@ For detailed guides, configuration, and examples, see the [full documentation](.
4242

4343
- [Installation Guide](./docs/installation.md) - Prerequisites and dependencies
4444
- [Configuration](./docs/configuration.md) - Input format and parameters
45+
- [Development Guide](./docs/development.md) - Development setup and extending the framework
4546

4647
---
4748

docs/development.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,48 @@
11
# Development Guide
22

3-
This guide explains how to extend InfiniMetrics by adding new adapters and metrics.
3+
This guide explains how to set up the development environment and extend InfiniMetrics by adding new adapters and metrics.
4+
5+
## Development Setup
6+
7+
### Pre-commit Setup
8+
9+
This project uses **pre-commit** to automatically enforce code style (Black) and linting (Flake8) before every commit.
10+
11+
#### Installation
12+
13+
```bash
14+
pip install pre-commit
15+
```
16+
17+
#### Setup (Run Once)
18+
19+
Run the following command in the project root directory to activate the git hooks:
20+
21+
```bash
22+
pre-commit install
23+
```
24+
25+
*Output should be: `pre-commit installed at .git/hooks/pre-commit`*
26+
27+
#### Usage
28+
29+
- **Automatic:** Just run `git commit` as usual.
30+
- If **Black** modifies your files: Run `git add .` again and re-commit.
31+
- If **Flake8** reports errors: Fix the errors, `git add`, and re-commit.
32+
- **Manual:** To check all files in the repository without committing:
33+
```bash
34+
pre-commit run --all-files
35+
```
36+
37+
#### Skip Checks (Emergency Only)
38+
39+
If you need to bypass the checks for a specific commit:
40+
41+
```bash
42+
git commit -m "your message" --no-verify
43+
```
44+
45+
---
446

547
## Adding a New Adapter
648

infinimetrics/adapter.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,15 @@ def _create_error_response(
104104
if test_input:
105105
response.update(
106106
{
107-
InfiniMetricsJson.RUN_ID: test_input.get(InfiniMetricsJson.RUN_ID, ""),
108-
InfiniMetricsJson.TESTCASE: test_input.get(InfiniMetricsJson.TESTCASE, ""),
109-
InfiniMetricsJson.CONFIG: test_input.get(InfiniMetricsJson.CONFIG, {}),
107+
InfiniMetricsJson.RUN_ID: test_input.get(
108+
InfiniMetricsJson.RUN_ID, ""
109+
),
110+
InfiniMetricsJson.TESTCASE: test_input.get(
111+
InfiniMetricsJson.TESTCASE, ""
112+
),
113+
InfiniMetricsJson.CONFIG: test_input.get(
114+
InfiniMetricsJson.CONFIG, {}
115+
),
110116
}
111117
)
112118

infinimetrics/common/constants.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ class InfiniCoreResult:
174174
STREAM_OPERATIONS = ["copy", "scale", "add", "triad"]
175175

176176
# Regex patterns for parsing hardware test output
177-
L1_CACHE_PATTERN = r"L1 Cache Bandwidth Sweep Test.*?Eff\. bw\s*-+\s*\n(.*?)(?=L2 Cache|\Z)"
177+
L1_CACHE_PATTERN = (
178+
r"L1 Cache Bandwidth Sweep Test.*?Eff\. bw\s*-+\s*\n(.*?)(?=L2 Cache|\Z)"
179+
)
178180
L2_CACHE_PATTERN = r"L2 Cache Bandwidth Sweep Test.*?Eff\. bw\s*-+\s*\n(.*?)(?=\Z)"
179181

180182
STREAM_PATTERN_TEMPLATE = r"STREAM_{op}\s+(\d+\.\d+)"
@@ -195,25 +197,27 @@ class InfiniCoreResult:
195197
# Error Code Constants
196198
# ============================================================
197199

200+
198201
class ErrorCode:
199202
"""Error code values for different types of failures, organized by severity layer"""
203+
200204
# Success
201-
SUCCESS = 0 # Test succeeded
205+
SUCCESS = 0 # Test succeeded
202206

203207
# Layer 1: Input/Configuration issues (not stability issues)
204-
CONFIG = 1 # Invalid configuration or input (user error)
208+
CONFIG = 1 # Invalid configuration or input (user error)
205209

206210
# Layer 2: Framework internal errors (tested framework's fault)
207-
INTERNAL = 2 # InfiniLM/InfiniCore internal error or non-zero return
211+
INTERNAL = 2 # InfiniLM/InfiniCore internal error or non-zero return
208212

209213
# Layer 3: Incompatibility issues
210-
INCOMPAT = 3 # Compilation errors, version incompatibility
214+
INCOMPAT = 3 # Compilation errors, version incompatibility
211215

212216
# Layer 4: System resource issues
213-
SYSTEM = 4 # OS/Hardware issues (OOM, disk full, GPU driver)
217+
SYSTEM = 4 # OS/Hardware issues (OOM, disk full, GPU driver)
214218

215219
# Layer 5: Test framework issues (our fault)
216-
GENERIC = 5 # Test framework logic error
220+
GENERIC = 5 # Test framework logic error
217221

218222
# Layer 6: Timeout issues
219-
TIMEOUT = 6 # Test started but hung/timeout
223+
TIMEOUT = 6 # Test started but hung/timeout

infinimetrics/common/csv_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def _sort_data(data: List[Dict[str, Any]], sort_by: str) -> List[Dict[str, Any]]
9191
Returns:
9292
Sorted list of dictionaries
9393
"""
94+
9495
def sort_key(x: Dict[str, Any]) -> float:
9596
# Handle explicit sort key
9697
if "_sort_key" in x:

infinimetrics/common/prompt_data.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,23 @@
1515
"What are the ethical considerations surrounding {topic}?",
1616
"How does {topic} impact our daily lives?",
1717
"What are the future trends in {topic}?",
18-
"What are the key challenges in {topic} research?"
18+
"What are the key challenges in {topic} research?",
1919
],
20-
2120
"general_qa": [
2221
"Tell me about {topic}.",
2322
"What is {topic}?",
2423
"Can you explain {topic}?",
2524
"I need information about {topic}.",
2625
"Please provide details about {topic}.",
27-
"Help me understand {topic}."
26+
"Help me understand {topic}.",
2827
],
29-
3028
"technical": [
3129
"Discuss the technical implementation of {topic}.",
3230
"What are the algorithms used in {topic}?",
3331
"Explain the architecture of {topic} systems.",
3432
"What are the performance considerations for {topic}?",
35-
"Describe the scalability challenges in {topic}."
36-
]
33+
"Describe the scalability challenges in {topic}.",
34+
],
3735
}
3836

3937
# ==================== Preset Topic Library ====================
@@ -48,9 +46,8 @@
4846
"neural networks",
4947
"transformers",
5048
"large language models",
51-
"generative AI"
49+
"generative AI",
5250
],
53-
5451
"tech": [
5552
"cloud computing",
5653
"blockchain technology",
@@ -60,38 +57,41 @@
6057
"distributed systems",
6158
"cybersecurity",
6259
"databases",
63-
"software engineering"
60+
"software engineering",
6461
],
65-
6662
"science": [
6763
"climate change",
6864
"genetic engineering",
6965
"space exploration",
7066
"renewable energy",
7167
"quantum physics",
7268
"biotechnology",
73-
"nanotechnology"
74-
]
69+
"nanotechnology",
70+
],
7571
}
7672

7773
# ==================== Default Configuration ====================
7874
DEFAULT_TEMPLATE_NAME = "ai_qa"
7975
DEFAULT_TOPIC_NAME = "ai_ml"
8076
DEFAULT_CHARS_PER_TOKEN = 4
8177

78+
8279
# ==================== Helper Functions ====================
8380
def get_template_names() -> list:
8481
"""Get all available template names"""
8582
return list(PRESET_TEMPLATES.keys())
8683

84+
8785
def get_topic_names() -> list:
8886
"""Get all available topic names"""
8987
return list(PRESET_TOPICS.keys())
9088

89+
9190
def get_template(template_name: str, fallback_name: str = "ai_qa") -> list:
9291
"""Get the template list for the specified name"""
9392
return PRESET_TEMPLATES.get(template_name, PRESET_TEMPLATES.get(fallback_name, []))
9493

94+
9595
def get_topics(topic_name: str, fallback_name: str = "ai_ml") -> list:
9696
"""Get the topic list for the specified name"""
9797
return PRESET_TOPICS.get(topic_name, PRESET_TOPICS.get(fallback_name, []))

0 commit comments

Comments
 (0)