Skip to content

Commit e34c376

Browse files
SkySingh04claude
andcommitted
fix: resolve all CI/CD issues
- Fix generate_json_report to return JSON content instead of filename - Fix line length issues (max 88 chars) in multiple files - Fix black formatting issues in code_generator.py, reporter.py, optimizer.py - Update docstrings to be more concise - All CI checks now passing (black, isort, flake8, mypy, tests) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3f52038 commit e34c376

6 files changed

Lines changed: 39 additions & 22 deletions

File tree

benchmarker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ def benchmark_latency(
8787
return 0.0, None
8888

8989
try: # Load interpreter
90-
interpreter = _tf.lite.Interpreter(model_path=model_path) # type: ignore[attr-defined]
90+
interpreter = _tf.lite.Interpreter( # type: ignore[attr-defined]
91+
model_path=model_path
92+
)
9193
interpreter.allocate_tensors()
9294
input_details = interpreter.get_input_details()
9395
if not input_details:

code_generator.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ def _generate_python_class(self) -> str:
205205
code += ' """Initialize the inference engine."""\n'
206206
code += f' self.model_path = model_path or "{model_path}"\n'
207207
code += f" self.buffer_size = {buffer_size}\n"
208-
code += f" self.memory_limit = {memory_limit} * 1024 * 1024 # Convert MB to bytes\n"
208+
code += (
209+
f" self.memory_limit = {memory_limit} * 1024 * 1024\n" # MB to bytes
210+
)
209211
code += f' self.optimize_for = "{optimize_for}"\n'
210212
code += " self.interpreter = None\n"
211213
code += " self.input_details = None\n"
@@ -301,7 +303,10 @@ def _generate_python_input_processing(self) -> str:
301303
code += " # Load image from file\n"
302304
code += " image = cv2.imread(input_data)\n"
303305
code += " if image is None:\n"
304-
code += ' raise ValueError(f"Could not load image: {input_data}")\n'
306+
code += (
307+
" raise ValueError("
308+
'f"Could not load image: {input_data}")\n'
309+
)
305310
code += " else:\n"
306311
code += " image = input_data\n"
307312
code += " \n"
@@ -426,7 +431,10 @@ def _generate_python_main(self) -> str:
426431
code += (
427432
' parser = argparse.ArgumentParser(description="EdgeFlow Inference")\n'
428433
)
429-
code += ' parser.add_argument("--input", required=True, help="Input data path")\n'
434+
code += (
435+
' parser.add_argument("--input", required=True, '
436+
'help="Input data path")\n'
437+
)
430438
code += ' parser.add_argument("--model", help="Model path override")\n'
431439
code += (
432440
' parser.add_argument("--benchmark", action="store_true", '
@@ -474,7 +482,8 @@ def _generate_cpp_code(self) -> str:
474482
code += " std::unique_ptr<tflite::Interpreter> interpreter_;\n"
475483
code += " std::unique_ptr<tflite::FlatBufferModel> model_;\n"
476484
code += f' int buffer_size_ = {self.config.get("buffer_size", 32)};\n'
477-
code += f' int memory_limit_ = {self.config.get("memory_limit", 64)} * 1024 * 1024;\n'
485+
mem_limit = self.config.get("memory_limit", 64)
486+
code += f" int memory_limit_ = {mem_limit} * 1024 * 1024;\n"
478487
code += " \n"
479488
code += "public:\n"
480489
code += " EdgeFlowInference(const std::string& model_path);\n"

edgeflow_ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def accept(self, visitor: "ASTVisitor") -> Any:
142142

143143
@dataclass
144144
class PipelineStatement(Statement):
145-
"""Represents a pipeline statement: pipeline: { preprocess, inference, postprocess }"""
145+
"""Pipeline statement: pipeline: { preprocess, inference, postprocess }"""
146146

147147
steps: List[str]
148148

optimizer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def optimize_model(self, config: Dict[str, Any]) -> Tuple[str, Dict[str, Any]]:
115115
try:
116116
created_baseline = False
117117

118-
# If we have a Keras source OR the baseline .tflite is missing, (re)create baseline
118+
# If we have Keras source OR baseline is missing, recreate
119119
if keras_source and (
120120
not os.path.exists(model_path)
121121
or keras_source.endswith((".h5", ".keras"))
@@ -188,9 +188,7 @@ def optimize_model(self, config: Dict[str, Any]) -> Tuple[str, Dict[str, Any]]:
188188
if os.path.isdir(model_path):
189189
converter = tf.lite.TFLiteConverter.from_saved_model(model_path)
190190
else:
191-
logger.warning(
192-
"Cannot perform quantization without a valid source graph; falling back"
193-
)
191+
logger.warning("Cannot quantize without valid source; falling back")
194192
return self._fallback_optimization(config)
195193

196194
# Apply quantization strategy

reporter.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ def generate_recommendations(improvements: Dict[str, float]) -> str:
134134
speedup = improvements.get("speedup", 0.0)
135135

136136
if size_red >= 70:
137-
recs.append(
138-
"- Excellent size reduction achieved! Model is now highly suitable for edge deployment"
139-
)
137+
recs.append("- Excellent size reduction! Model highly suitable for edge")
140138
elif size_red >= 50:
141139
recs.append(
142140
"- Good size reduction achieved; consider further quantization or pruning"
@@ -209,7 +207,7 @@ def generate_report(
209207
210208
✨ **Model successfully optimized using EdgeFlow DSL** ✨
211209
212-
The EdgeFlow compiler has successfully optimized your model with the following impressive results:
210+
EdgeFlow successfully optimized your model with these results:
213211
214212
- **Size Reduction**: {improvements['size_reduction']:.1f}%
215213
- **Speed Improvement**: {improvements['speedup']:.1f}x faster
@@ -228,7 +226,7 @@ def generate_report(
228226
| **Model Size** | {unoptimized_stats['size_mb']:.2f} MB | \
229227
{optimized_stats['size_mb']:.2f} MB | ↓ {improvements['size_reduction']:.1f}% |
230228
| **Inference Latency** | {unoptimized_stats['latency_ms']:.2f} ms | \
231-
{optimized_stats['latency_ms']:.2f} ms | ↓ {improvements['latency_reduction']:.1f}% |
229+
{optimized_stats['latency_ms']:.2f} ms | ↓ {improvements['latency_reduction']:.1f}% |
232230
| **Throughput** | {1000/float(unoptimized_stats['latency_ms']):.1f} fps | \
233231
{1000/float(optimized_stats['latency_ms']):.1f} fps | \
234232
{improvements['throughput_increase']:.1f}% |
@@ -244,7 +242,8 @@ def generate_report(
244242
### Technique Applied
245243
- **Quantization**: INT8 quantization applied
246244
- **Target Device**: {config.get('target_device', 'Generic') if config else 'Generic'}
247-
- **Optimization Goal**: {config.get('optimize_for', 'Balanced') if config else 'Balanced'}
245+
- **Optimization Goal**: \
246+
{config.get('optimize_for', 'Balanced') if config else 'Balanced'}
248247
249248
### Benefits Achieved
250249
1. **Reduced Storage Requirements**: Your model now requires \
@@ -283,7 +282,11 @@ def generate_json_report(
283282
config: Optional[Dict[str, Any]] = None,
284283
output_path: str = "report.json",
285284
) -> str:
286-
"""Generate machine-readable JSON report for API consumption."""
285+
"""Generate machine-readable JSON report for API consumption.
286+
287+
Returns:
288+
JSON string containing the report data
289+
"""
287290
# Validate minimal fields
288291
required_fields = ["size_mb", "latency_ms"]
289292
for field in required_fields:
@@ -299,7 +302,12 @@ def generate_json_report(
299302
"timestamp": datetime.now().isoformat(),
300303
}
301304

302-
output = Path(output_path)
303-
output.write_text(json.dumps(payload, indent=2))
304-
logger.info("JSON report successfully generated: %s", output)
305-
return str(output)
305+
json_content = json.dumps(payload, indent=2)
306+
307+
# Optionally write to file if output_path is provided
308+
if output_path:
309+
output = Path(output_path)
310+
output.write_text(json_content)
311+
logger.info("JSON report successfully generated: %s", output)
312+
313+
return json_content

tests/test_reporter_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_cli_integration(self):
2727
text=True,
2828
)
2929

30-
# Basic sanity: process should exit (0 or non-zero tolerated in CI simulation)
30+
# Process should exit (0 or non-zero tolerated in CI)
3131
assert result.returncode in (0, 1, 2)
3232

3333
# Check that report was generated

0 commit comments

Comments
 (0)