Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions .github/workflows/sanity-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,25 @@ jobs:
id: find_files
run: |
FILES=$(git diff --diff-filter=A --name-only origin/main...HEAD | grep "_i8_" || true)
{
echo "files<<EOF"
if [ -z "$FILES" ]; then
COUNT=0
echo "No i8 files found"
else
COUNT=$(echo "$FILES" | wc -l | tr -d ' ')
echo "Found $COUNT i8 file(s):"
echo "$FILES"
echo "EOF"
} >> $GITHUB_OUTPUT
fi
echo "count=$COUNT" >> $GITHUB_OUTPUT
echo "files<<EOF" >> $GITHUB_OUTPUT
echo "$FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Run model checks
if: steps.find_files.outputs.files != ''
if: steps.find_files.outputs.count != '0'
run: |
while read -r f; do
[ -z "$f" ] && continue
echo "Checking model: $f"
git lfs pull --include="$f" --exclude=""
python CI/check_model.py --model "$f"
done <<< "${{ steps.find_files.outputs.files }}"

python CI/post_filter.py -- CI/check_model.py --models "$f"
done <<< "${{ steps.find_files.outputs.files }}"
13 changes: 7 additions & 6 deletions CI/check_model.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import argparse
import os

import akida
from cnn2snn import convert
from quantizeml import load_model

from compute_device import compute_min_device


def process_model(file_path):
try:
print(f"Loading model: {file_path}")
Expand All @@ -29,8 +27,11 @@ def process_model(file_path):

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--model", required=True, help="Path to model file (.h5 or .onnx)")
parser.add_argument("--models", nargs="+", required=True,
help="Path to model files (.h5 or .onnx)")
args = parser.parse_args()

process_model(args.model)

# Process each model
for model_file in args.models:
if os.path.exists(model_file):
process_model(model_file)
Comment on lines +36 to +37
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe you are able to simplify this as :

Suggested change
if os.path.exists(model_file):
# Move this step of the YAML workflow into the Python script
# Download the file via Git LFS if necessary
# git lfs pull --include="$f" --exclude=""
subprocess.run(["git", "lfs", "pull",
"--include", model_file,"--exclude", ""],
capture_output=True)
process_model(model_file)
process_model(model_file)

To avoid to change the previous script approach

69 changes: 69 additions & 0 deletions CI/post_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Simple post-capture filter for noisy commands.
Runs a subprocess, captures stdout+stderr, and prints allowed lines to the console.
Usage:
python CI/post_filter.py -- CI/check_model.py --models $FILES
The `--` separates options to this script from the command to run.
"""
import os
import sys
import argparse
import subprocess
import re

def run_and_filter(cmd:str):
"""Runs a subprocess, captures stdout+stderr, and prints filtred lines to the console.
Args:
cmd (str): Python command sent from GitHub action
"""
allow = re.compile(r'(Checking model:|Loading model:|✅.*needs \d+ Akida nodes)', re.IGNORECASE)
deny = re.compile(
r'(cuda|cufft|cudnn|cublas|tensorflow|xla|absl::InitializeLog|Unable to register|WARNING:|'
r'failed call to|loop_optimizer\.cc|computation_placer|computation placer|gpu_device|Created device|'
r'TF_FORCE_GPU_ALLOW_GROWTH|Overriding orig_value)'
, re.IGNORECASE)

# If the command is a Python script path and not executable, prefix
# with the current Python interpreter to avoid PermissionError on CI.
if isinstance(cmd, (list, tuple)) and cmd:
first = cmd[0]
if isinstance(first, str) and first.endswith('.py') and not os.access(first, os.X_OK):
cmd = [sys.executable] + list(cmd)

proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)

try:
# Read lines as they arrive and print
for raw in iter(proc.stdout.readline, ''):
if raw is None:
break
line = raw.rstrip('\n')
keep = allow.search(line) or not deny.search(line)
if keep:
print(line, flush=True)

proc.wait()
finally:
try:
proc.stdout.close()
except Exception:
pass

def main(argv=None):
p = argparse.ArgumentParser(prog='post_filter', description='Run command and filter its output')
p.add_argument('cmd', nargs=argparse.REMAINDER, help='Command to run (use -- before the command)')
args = p.parse_args(argv)

if not args.cmd:
print('No command provided.'
'Use -- to separate command, e.g.: python CI/post_filter.py -- CI/check_model.py --models $FILES')
return 2

# Remove leading '--' if present
cmd = args.cmd
if cmd and cmd[0] == '--':
cmd = cmd[1:]

run_and_filter(cmd)

if __name__ == '__main__':
sys.exit(main())