Skip to content

Commit dc0ae51

Browse files
committed
Code format && fix E821 error
1 parent 215e23e commit dc0ae51

16 files changed

Lines changed: 245 additions & 122 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ repos:
77
rev: 6.1.0
88
hooks:
99
- id: flake8
10+
args: ['--exit-zero', '--show-source', '--statistics'] # Show all warnings with details

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, []))

infinimetrics/common/testcase_utils.py

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@
1818
def parse_testcase(testcase_str: str) -> tuple[str, str]:
1919
"""
2020
Parse testcase string to extract framework and mode
21-
21+
2222
Args:
2323
testcase_str: testcase string, e.g., "infer.InfiniLM.Direct"
24-
24+
2525
Returns:
26-
tuple: (mode, framework) where mode is "direct" or "service",
26+
tuple: (mode, framework) where mode is "direct" or "service",
2727
framework is lowercase framework name
28-
28+
2929
Raises:
3030
ValueError: if cannot determine framework
3131
"""
3232
testcase_lower = testcase_str.lower()
33-
33+
3434
# Determine mode
3535
if "service" in testcase_lower:
3636
mode = "service"
3737
elif "direct" in testcase_lower:
3838
mode = "direct"
3939
else:
4040
mode = "direct" # default mode
41-
41+
4242
# Determine framework (more flexible parsing)
4343
if "vllm" in testcase_lower:
4444
framework = "vllm"
@@ -50,27 +50,37 @@ def parse_testcase(testcase_str: str) -> tuple[str, str]:
5050
framework = "infinitrain"
5151
else:
5252
# Try to extract from dot-separated parts
53-
parts = testcase_str.split('.')
53+
parts = testcase_str.split(".")
5454
if len(parts) < 2:
55-
raise ValueError(f"Cannot determine framework from testcase: {testcase_str}")
56-
55+
raise ValueError(
56+
f"Cannot determine framework from testcase: {testcase_str}"
57+
)
58+
5759
framework_candidate = parts[-2].lower()
58-
if framework_candidate not in ["infinilm", "vllm", "bmtrain", "megatron", "infinitrain"]:
59-
raise ValueError(f"Cannot determine framework from testcase: {testcase_str}")
60-
60+
if framework_candidate not in [
61+
"infinilm",
62+
"vllm",
63+
"bmtrain",
64+
"megatron",
65+
"infinitrain",
66+
]:
67+
raise ValueError(
68+
f"Cannot determine framework from testcase: {testcase_str}"
69+
)
70+
6171
framework = framework_candidate
62-
72+
6373
return mode, framework
6474

6575

6676
def generate_run_id(testcase: str, user_run_id: Optional[str] = None) -> str:
6777
"""
6878
Generate or enhance run_id
69-
79+
7080
Args:
7181
testcase: testcase string
7282
user_run_id: user-provided run_id (optional)
73-
83+
7484
Returns:
7585
Generated run_id
7686
"""
@@ -79,12 +89,13 @@ def generate_run_id(testcase: str, user_run_id: Optional[str] = None) -> str:
7989
else:
8090
return generate_auto_run_id(testcase)
8191

92+
8293
def generate_run_id_from_config(config_dict: Dict[str, Any]) -> str:
8394
"""Generate run_id from configuration dictionary"""
8495
outer_run_id = config_dict.get("run_id")
8596
outer_testcase = config_dict.get("testcase")
8697
config_data = config_dict.get("config", {})
87-
98+
8899
# Validate testcase position
89100
inner_testcase = config_data.get("testcase")
90101
if outer_testcase:
@@ -97,24 +108,27 @@ def generate_run_id_from_config(config_dict: Dict[str, Any]) -> str:
97108
)
98109
else:
99110
raise ValueError("testcase is required at the outer level of the config.")
100-
111+
101112
# Validate run_id position
102113
inner_run_id = config_data.get("run_id")
103114
if inner_run_id:
104115
raise ValueError(
105116
"run_id must be at the outer level, not inside 'config'. "
106117
f"Found: '{inner_run_id}' inside 'config'."
107118
)
108-
119+
109120
# Generate run_id using the existing function
110121
return generate_run_id(outer_testcase, outer_run_id)
111122

123+
112124
def enhance_user_run_id(user_run_id: str) -> str:
113125
"""Enhance user-provided run_id by adding timestamp and random code"""
114126
# If already contains timestamp and random code, return directly
115-
timestamp_pattern = r'\.\d{8}_\d{6}\.[a-z0-9]{8}$'
127+
timestamp_pattern = r"\.\d{8}_\d{6}\.[a-z0-9]{8}$"
116128
if re.search(timestamp_pattern, user_run_id):
117-
logger.info(f"User run_id already contains timestamp and random code: {user_run_id}")
129+
logger.info(
130+
f"User run_id already contains timestamp and random code: {user_run_id}"
131+
)
118132
return user_run_id
119133

120134
# Clean user run_id
@@ -124,7 +138,7 @@ def enhance_user_run_id(user_run_id: str) -> str:
124138
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
125139

126140
# 8-character random code
127-
random_suffix = ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))
141+
random_suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
128142

129143
# Combine
130144
enhanced_run_id = f"{cleaned_user_id}.{timestamp}.{random_suffix}"
@@ -142,7 +156,7 @@ def generate_auto_run_id(testcase: str) -> str:
142156
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
143157

144158
# 8-character random code
145-
random_suffix = ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))
159+
random_suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
146160

147161
# Combine
148162
run_id = f"{cleaned_testcase}.{timestamp}.{random_suffix}"
@@ -153,28 +167,28 @@ def generate_auto_run_id(testcase: str) -> str:
153167
def validate_testcase_format(testcase: str) -> bool:
154168
"""Validate testcase format"""
155169
# Basic validation: should contain at least 2 parts separated by dots
156-
parts = testcase.split('.')
170+
parts = testcase.split(".")
157171
if len(parts) < 2:
158172
return False
159-
173+
160174
# Should contain valid mode
161175
testcase_lower = testcase.lower()
162176
if not ("direct" in testcase_lower or "service" in testcase_lower):
163177
return False
164-
178+
165179
return True
166180

167181

168182
def extract_testcase_components(testcase: str) -> dict:
169183
"""Extract components from testcase string"""
170-
parts = testcase.split('.')
171-
184+
parts = testcase.split(".")
185+
172186
result = {
173187
"full": testcase,
174188
"parts": parts,
175189
"domain": parts[0] if len(parts) > 0 else "",
176190
"framework": parts[1] if len(parts) > 1 else "",
177-
"mode": "service" if "service" in testcase.lower() else "direct"
191+
"mode": "service" if "service" in testcase.lower() else "direct",
178192
}
179-
193+
180194
return result

0 commit comments

Comments
 (0)