Skip to content

feat(ml): add GPU/Kaggle-ready training harness with presets, resume and ONNX export - #28

Merged
Mani212005 merged 2 commits into
mainfrom
fm/digisim-t5-trainharness
Nov 17, 2026
Merged

Mani212005 merged 2 commits into
mainfrom
fm/digisim-t5-trainharness

Conversation

@Mani212005

Copy link
Copy Markdown
Owner

Intent

DigiSim is a neglected project. Pull up the latest changes in Linux. It is high time to start training the model for it. I have not been able to provide the data. Figure out, get the data, train a model, make improvements and fix that. Do not come to me until you absolutely need me.

Context: a scout report found that the only trained detector uses 12 gate-era classes and detects nothing on the transistor-first schematics the app now uses, that the transistor-level training data does not exist yet, and that the wire/net tracing assumes left-to-right gates. It split the work into tasks T1-T11; this change is one of them, "T5 - Training harness for GPU/Kaggle" (T1, the class schema ml/classes.yaml as the single source of truth, is already merged). The substance of T5 from the report: refactor ml/train.py so it takes --device, --data, --imgsz, --model, supports resume, defaults --workers from the CPU count, and has no hardcoded cpu device (the old script hardcoded cpu in three places, always copied weights to a gitignored path and had no GPU/Kaggle path or resume); provide stage A (synthetic pretrain) and stage B (mixed fine-tune with real-image oversampling) as presets; and write ml/kaggle/train_kaggle.py as a single file that installs ultralytics, reads the dataset from /kaggle/input, and writes best.pt, an ONNX export and metrics.json. Real training is meant to run on Kaggle GPUs (DDP, device 0,1,2,3) while the laptop only does smoke runs. Acceptance from the report: a CPU smoke run of 2 epochs on 200 images completes in CI-like conditions and produces metrics.json and an ONNX file; the script runs unchanged on device=0,1,2,3 (checked by a dry-run flag); ruff clean. Class vocabulary must come from ml/classes.yaml; no weights, datasets or images are committed. No Kaggle or Roboflow credentials exist, so nothing here logs in to or uploads to Kaggle.

What Changed

  • Rewrote ml/train.py as a device-agnostic harness: --device cpu|auto|0|0,1,2,3 (multi-index runs DDP, with no hardcoded cpu), --data, --model, --imgsz, --batch (total across GPUs), --workers (defaults from the CPU count), --resume RUN_DIR and --dry-run (prints the resolved plan without importing torch). Added smoke, stage-a (synthetic pretrain) and stage-b (mixed fine-tune with --real-train oversampling via --real-oversample) presets. Training checks data.yaml class names against ml/classes.yaml, and each run folder gets best.pt, best.onnx and metrics.json (per-class P/R/F1/AP/accuracy, F1/accuracy gate verdict, environment, dataset counts). Copying weights to the gitignored install path is now opt-in (--install-weights).
  • Added ml/kaggle/train_kaggle.py, a single-file Kaggle twin that pip-installs ultralytics/onnx, finds data.yaml under /kaggle/input, ignores Jupyter kernel args, supports --dry-run and --resume, and writes the same artifacts to /kaggle/working/digisim_run. It does not log in to or upload anything to Kaggle. Added ml/make_smoke_dataset.py, which generates a throwaway procedural YOLO dataset for harness checks, plus onnx, onnxslim and onnxruntime dependencies in ml/pyproject.toml (with ml/uv.lock).
  • Added ml/tests/test_train_harness.py covering device parsing, batch and worker defaults, device pass-through to ultralytics with CPU export, resume keeping real-image oversampling, a preset-parity check between train.py and the Kaggle script, dry-run for several device specs, class-drift detection, mixed-dataset leakage blocking and metrics assembly. It also contains a 2-epoch CPU smoke run gated behind DIGISIM_ML_SMOKE=1. Updated agent_docs/ml-pipeline.md with a Training Harness section and the Kaggle training row.

Risk Assessment

⚠️ Medium: The harness logic is sound and the class vocabulary comes from classes.yaml with no weights or credentials committed, but resume of a mixed stage-B run silently loses its oversampling and mis-records config and metrics, and one test only greps source text.

Testing

I drove the real harness end to end on CPU. Stage-A and Kaggle dry-runs with device 0,1,2,3 resolved to DDP with world size 4 and batch 64, and the CLI rejected a mistyped argument. A real 2-epoch smoke run (train.py) and a Kaggle-layout smoke run both produced best.pt, best.onnx and metrics.json. A stage-B run interrupted after one epoch resumed from epoch 2 and kept the real-image oversampling (still 4x in train_mixed.txt, config.yaml and metrics.json), and the harness test file passed. No GPU is available here, so actual multi-GPU DDP execution was only checked through the dry-run plan. There is no UI, so there are no screenshots; evidence is CLI logs and JSON in the evidence directory.

  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
CPU smoke run: 2 epochs on 200 images produces best.pt, best.onnx and metrics.json ✅ pass live smoke_run.log, smoke_metrics.json; run dir contained best.pt, best.onnx, metrics.json
Dry-run with device 0,1,2,3 resolves to a 4-process DDP plan (train.py and the Kaggle script) without needing GPUs ✅ pass live dryrun_train.txt, kaggle_dryrun.txt (world_size 4, ddp true, batch 64)
Kaggle script reads a dataset from an input root and writes best.pt, ONNX and metrics.json ✅ pass live kaggle_smoke.log (rc=0; output folder had best.onnx, best.pt, metrics.json, config.yaml, data.yaml)
Adversarial: a mistyped Kaggle CLI argument (--real_train) is rejected instead of silently ignored ✅ pass live CLI output: 'unrecognized arguments: --real_train x'
Adversarial: stage-B resume after an interruption keeps real-image oversampling ✅ pass live stageb_resume.log ('Resuming ... from epoch 2 to 4'); train_mixed.txt checksum unchanged; config.yaml real_oversample 4; metrics.json dataset.real_oversample 4
Adversarial: real training images that overlap val/test are refused ✅ pass live stageb_run1.log: 'error: 30 real training image(s) are also in val/test'
Real multi-GPU DDP training on device 0,1,2,3 ⏸️ untested no This machine has no NVIDIA GPU (nvidia-smi is absent). Multi-GPU training needs a Kaggle GPU runtime, and no Kaggle credentials exist, so the dry-run flag is the agreed check.
Evidence: CPU smoke run log (2 epochs, train, val, ONNX export)

�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 2% ──────────── 128.0KB/6.2MB 1.2MB/s 0.1s<4.9s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 4% ╸─────────── 272.0KB/6.2MB 1.2MB/s 0.2s<5.0s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 6% ╸─────────── 432.0KB/6.2MB 1.4MB/s 0.3s<4.2s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 9% ━─────────── 592.0KB/6.2MB 1.5MB/s 0.4s<3.7s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 12% ━╸────────── 800.0KB/6.2MB 1.9MB/s 0.5s<2.9s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 18% ━━────────── 1.1/6.2MB 3.2MB/s 0.6s<1.6s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 22% ━━╸───────── 1.4/6.2MB 2.7MB/s 0.8s<1.8s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 28% ━━━───────── 1.8/6.2MB 3.8MB/s 0.9s<1.2s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 34% ━━━━──────── 2.2/6.2MB 3.5MB/s 1.0s<1.2s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 40% ━━━━╸─────── 2.5/6.2MB 3.0MB/s 1.1s<1.3s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 45% ━━━━━─────── 2.8/6.2MB 3.1MB/s 1.2s<1.1s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 50% ━━━━━━────── 3.2/6.2MB 3.4MB/s 1.3s<0.9s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 56% ━━━━━━╸───── 3.5/6.2MB 3.6MB/s 1.4s<0.8s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 62% ━━━━━━━╸──── 3.9/6.2MB 3.7MB/s 1.5s<0.6s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 68% ━━━━━━━━──── 4.3/6.2MB 3.4MB/s 1.6s<0.6s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 73% ━━━━━━━━╸─── 4.6/6.2MB 3.4MB/s 1.7s<0.5s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 79% ━━━━━━━━━╸── 5.0/6.2MB 3.4MB/s 1.8s<0.4s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 85% ━━━━━━━━━━── 5.3/6.2MB 3.9MB/s 1.9s<0.2s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 92% ━━━━━━━━━━━─ 5.8/6.2MB 3.8MB/s 2.0s<0.1s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 97% ━━━━━━━━━━━╸ 6.1/6.2MB 3.4MB/s 2.1s<0.0s
�[KDownloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolov8n.pt to 'yolov8n.pt': 100% ━━━━━━━━━━━━ 6.2MB 2.9MB/s 2.1s
New https://pypi.org/project/ultralytics/8.4.215 available 😃 Update with 'pip install -U ultralytics'
Ultralytics 8.4.86 🚀 Python-3.14.6 torch-2.12.1+cu130 CPU (12th Gen Intel Core i7-1255U)
�[34m�[1mengine/trainer: �[0magnostic_nms=False, amp=True, angle=1.0, augment=False, auto_augment=randaugment, batch=8, bgr=0.0, box=7.5, cache=False, cfg=None, classes=None, close_mosaic=0, cls=0.5, cls_pw=0.0, compile=False, conf=None, copy_paste=0.0, copy_paste_mode=flip, cos_lr=False, cutmix=0.0, data=~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/data/data.yaml, degrees=0.0, deterministic=True, device=cpu, dfl=1.5, dis=6.0, distill_model=None, dnn=False, dropout=0.0, dynamic=False, embed=None, end2end=None, epochs=2, erasing=0.4, exist_ok=True, fliplr=0.5, flipud=0.0, format=torchscript, fraction=1.0, freeze=None, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, imgsz=320, iou=0.7, keras=False, kobj=1.0, line_width=None, lr0=0.01, lrf=0.01, mask_ratio=4, max_det=300, mixup=0.0, mode=train, model=yolov8n.pt, momentum=0.937, mosaic=1.0, multi_scale=0.0, name=train, nbs=64, nms=False, opset=None, optimize=False, optimizer=auto, overlap_mask=True, patience=2, perspective=0.0, plots=False, pose=12.0, pretrained=True, profile=False, project=~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke, quantize=None, rect=False, resume=False, retina_masks=False, rle=1.0, save=True, save_conf=False, save_crop=False, save_dir=~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke/train, save_frames=False, save_json=False, save_period=-1, save_txt=False, scale=0.5, seed=0, shear=0.0, show=False, show_boxes=True, show_conf=True, show_labels=True, simplify=True, single_cls=False, source=None, split=val, stream_buffer=False, task=detect, time=None, tracker=tracktrack.yaml, translate=0.1, val=True, verbose=True, vid_stride=1, visualize=False, warmup_bias_lr=0.1, warmup_epochs=0.0, warmup_momentum=0.8, weight_decay=0.0005, workers=8, workspace=None
Overriding model.yaml nc=80 with nc=14

                   from  n    params  module                                       arguments                     
  0                  -1  1       464  ultralytics.nn.modules.conv.Conv             [3, 16, 3, 2]                 
  1                  -1  1      4672  ultralytics.nn.modules.conv.Conv             [16, 32, 3, 2]                
  2                  -1  1      7360  ultralytics.nn.modules.block.C2f             [32, 32, 1, True]             
  3                  -1  1     18560  ultralytics.nn.modules.conv.Conv             [32, 64, 3, 2]                
  4                  -1  2     49664  ultralytics.nn.modules.block.C2f             [64, 64, 2, True]             
  5                  -1  1     73984  ultralytics.nn.modules.conv.Conv             [64, 128, 3, 2]               
  6                  -1  2    197632  ultralytics.nn.modules.block.C2f             [128, 128, 2, True]           
  7                  -1  1    295424  ultralytics.nn.modules.conv.Conv             [128, 256, 3, 2]              
  8                  -1  1    460288  ultralytics.nn.modules.block.C2f             [256, 256, 1, True]           
  9                  -1  1    164608  ultralytics.nn.modules.block.SPPF            [256, 256, 5]                 
 10                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']          
 11             [-1, 6]  1         0  ultralytics.nn.modules.conv.Concat           [1]                           
 12                  -1  1    148224  ultralytics.nn.modules.block.C2f             [384, 128, 1]                 
 13                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']          
 14             [-1, 4]  1         0  ultralytics.nn.modules.conv.Concat           [1]                           
 15                  -1  1     37248  ultralytics.nn.modules.block.C2f             [192, 64, 1]                  
 16                  -1  1     36992  ultralytics.nn.modules.conv.Conv             [64, 64, 3, 2]                
 17            [-1, 12]  1         0  ultralytics.nn.modules.conv.Concat           [1]                           
 18                  -1  1    123648  ultralytics.nn.modules.block.C2f             [192, 128, 1]                 
 19                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]              
 20             [-1, 9]  1         0  ultralytics.nn.modules.conv.Concat     

... [6667 bytes truncated] ...

18        320: 55% ━━━━━━╸───── 10/18 2.4it/s 4.5s<3.3s
�[K        2/2         0G      1.193      3.624     0.9676         26        320: 61% ━━━━━━━───── 11/18 2.4it/s 4.9s<2.9s
�[K        2/2         0G      1.187      3.596     0.9695         18        320: 66% ━━━━━━━━──── 12/18 2.5it/s 5.2s<2.4s
�[K        2/2         0G       1.18      3.594     0.9674         17        320: 72% ━━━━━━━━╸─── 13/18 2.4it/s 5.7s<2.1s
�[K        2/2         0G      1.169      3.584     0.9675         19        320: 77% ━━━━━━━━━─── 14/18 2.2it/s 6.2s<1.8s
�[K        2/2         0G      1.153      3.557     0.9577         21        320: 83% ━━━━━━━━━━── 15/18 2.4it/s 6.6s<1.3s
�[K        2/2         0G      1.143      3.539     0.9531         20        320: 88% ━━━━━━━━━━╸─ 16/18 2.5it/s 7.0s<0.8s
�[K        2/2         0G      1.135      3.551     0.9474         13        320: 94% ━━━━━━━━━━━─ 17/18 3.1it/s 7.2s<0.3s
�[K        2/2         0G      1.135      3.551     0.9474         13        320: 100% ━━━━━━━━━━━━ 18/18 2.5it/s 7.2s

�[K                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 50% ━━━━━━────── 1/2 1.1s/it 0.3s<1.1s
�[K                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% ━━━━━━━━━━━━ 2/2 3.4it/s 0.6s
                   all         30         51     0.0266      0.848      0.134     0.0865

2 epochs completed in 0.004 hours.
Optimizer stripped from ~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke/train/weights/last.pt, 6.2MB
Optimizer stripped from ~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke/train/weights/best.pt, 6.2MB

Validating ~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke/train/weights/best.pt...
Ultralytics 8.4.86 🚀 Python-3.14.6 torch-2.12.1+cu130 CPU (12th Gen Intel Core i7-1255U)
Model summary (fused): 73 layers, 3,008,378 parameters, 0 gradients, 8.1 GFLOPs

�[K                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 50% ━━━━━━────── 1/2 1.1it/s 0.3s<1.0s
�[K                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% ━━━━━━━━━━━━ 2/2 3.8it/s 0.5s
                   all         30         51     0.0269      0.848      0.134     0.0865
                  NMOS          5          5      0.011        0.2     0.0065    0.00325
                  PMOS          3          3     0.0435          1      0.103     0.0582
                   VDD          1          2    0.00926          1      0.138     0.0718
                   GND          4          4       0.04          1      0.121     0.0594
            INPUT_PORT          5          5     0.0331          1     0.0634     0.0365
           OUTPUT_PORT          2          2     0.0108          1      0.266      0.181
              JUNCTION          4          4     0.0339          1      0.433      0.331
                   AND          3          3     0.0222      0.667     0.0817     0.0505
                    OR          3          3          0          0          0          0
                   NOT          3          3     0.0214          1     0.0822     0.0588
                  NAND          3          3     0.0186          1     0.0907     0.0637
                   NOR          6          6     0.0522          1      0.196      0.109
                   XOR          6          6     0.0594          1      0.107     0.0655
                  XNOR          2          2     0.0208          1       0.19      0.124
Speed: 0.3ms preprocess, 16.2ms inference, 0.0ms loss, 0.2ms postprocess per image
Ultralytics 8.4.86 🚀 Python-3.14.6 torch-2.12.1+cu130 CPU (12th Gen Intel Core i7-1255U)
Model summary (fused): 73 layers, 3,008,378 parameters, 0 gradients, 8.1 GFLOPs
�[34m�[1mval: �[0mFast image access ✅ (ping: 0.0±0.0 ms, read: 1860.2±603.5 MB/s, size: 18.1 KB)

�[K�[34m�[1mval: �[0mScanning ~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/data/labels/test... 30 images, 0 backgrounds, 0 corrupt: 100% ━━━━━━━━━━━━ 30/30 3.1Kit/s 0.0s
�[34m�[1mval: �[0mNew cache created: ~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/data/labels/test.cache

�[K                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 25% ━━━───────── 1/4 2.1it/s 0.1s<1.4s
�[K                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 50% ━━━━━━────── 2/4 3.0it/s 0.3s<0.7s
�[K                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 75% ━━━━━━━━━─── 3/4 3.6it/s 0.5s<0.3s
�[K                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% ━━━━━━━━━━━━ 4/4 5.6it/s 0.7s
                   all         30         57     0.0268      0.893      0.153     0.0846
                  NMOS          5          6     0.0323        0.5      0.182     0.0196
                  PMOS          4          4     0.0513          1     0.0971     0.0449
                   VDD          6          6     0.0279          1      0.252      0.119
                   GND          4          4     0.0333          1      0.165      0.116
            INPUT_PORT          5          5     0.0256          1     0.0858     0.0527
           OUTPUT_PORT          1          2    0.00897          1     0.0977     0.0603
              JUNCTION          4          4     0.0328          1      0.444      0.327
                   AND          3          3     0.0278          1     0.0881     0.0658
                    OR          4          4          0          0          0          0
                   NOT          3          3     0.0194          1     0.0464     0.0291
                  NAND          6          7     0.0374          1      0.223      0.164
                   NOR          3          3     0.0242          1      0.306      0.101
                   XOR          2          2     0.0194          1     0.0452     0.0167
                  XNOR          3          4     0.0354          1       0.11     0.0679
Speed: 0.2ms preprocess, 18.9ms inference, 0.0ms loss, 0.3ms postprocess per image
Results saved to �[1m/home/mani/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke/val�[0m
Ultralytics 8.4.86 🚀 Python-3.14.6 torch-2.12.1+cu130 CPU (12th Gen Intel Core i7-1255U)
💡 ProTip: Export to OpenVINO format for best performance on Intel hardware. Learn more at https://docs.ultralytics.com/integrations/openvino/

�[34m�[1mPyTorch:�[0m starting from '~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke/train/weights/best.pt' with input shape (1, 3, 320, 320) BCHW and output shape(s) (1, 18, 2100) (5.9 MB)

�[34m�[1mONNX:�[0m starting export with onnx 1.23.2 opset 17...
�[34m�[1mONNX:�[0m slimming with onnxslim 0.1.99...
�[34m�[1mONNX:�[0m export success ✅ 0.9s, saved as '~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke/train/weights/best.onnx' (11.6 MB)

Export complete (0.9s)
Results saved to �[1m/home/mani/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke/train/weights/best.onnx�[0m
Predict:         yolo predict task=detect model=~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke/train/weights/best.onnx imgsz=320 
Validate:        yolo val task=detect model=~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke/train/weights/best.onnx imgsz=320 data=~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/data/data.yaml  
Visualize:       https://netron.app

Run logged to ~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke  (best.pt, best.onnx, metrics.json)
Run `uv run python evaluate.py` for the per-class F1/accuracy gate.
Evidence: smoke metrics.json
{
  "schema_version": 1,
  "run_name": "smoke",
  "preset": "smoke",
  "map50": 0.153008865770106,
  "map50_95": 0.08461676480546694,
  "mean_precision": 0.026839426599965327,
  "mean_recall": 0.8928571428571429,
  "eval_split": "test",
  "per_class": {
    "NMOS": {
      "precision": 0.03225806451612903,
      "recall": 0.5,
      "f1": 0.060606060606060594,
      "ap50": 0.18177966101694915,
      "ap50_95": 0.019625334522747548,
      "instances": 6.0,
      "accuracy": 0.0
    },
    "PMOS": {
      "precision": 0.05128205128205128,
      "recall": 1.0,
      "f1": 0.09756097560975609,
      "ap50": 0.09707317073170732,
      "ap50_95": 0.0448780487804878,
      "instances": 4.0,
      "accuracy": 0.0
    },
    "VDD": {
      "precision": 0.027906976744186046,
      "recall": 1.0,
      "f1": 0.05429864253393665,
      "ap50": 0.2524910394265233,
      "ap50_95": 0.11947894265232975,
      "instances": 6.0,
      "accuracy": 0.0
    },
    "GND": {
      "precision": 0.03333333333333333,
      "recall": 1.0,
      "f1": 0.06451612903225806,
      "ap50": 0.16499999999999998,
      "ap50_95": 0.11631666666666665,
      "instances": 4.0,
      "accuracy": 0.0
    },
    "INPUT_PORT": {
      "precision": 0.02564102564102564,
      "recall": 1.0,
      "f1": 0.05,
      "ap50": 0.08584291187739464,
      "ap50_95": 0.0526684227330779,
      "instances": 5.0,
      "accuracy": 0.0
    },
    "OUTPUT_PORT": {
      "precision": 0.008968609865470852,
      "recall": 1.0,
      "f1": 0.017777777777777778,
      "ap50": 0.09774131274131276,
      "ap50_95": 0.060310810810810814,
      "instances": 2.0,
      "accuracy": 0.0
    },
    "JUNCTION": {
      "precision": 0.03278688524590164,
      "recall": 1.0,
      "f1": 0.06349206349206349,
      "ap50": 0.44386363636363646,
      "ap50_95": 0.3269005681818183,
      "instances": 4.0,
      "accuracy": 0.0
    },
    "AND": {
      "precision": 0.027777777777777776,
      "recall": 1.0,
      "f1": 0.05405405405405406,
      "ap50": 0.08807969083155648,
      "ap50_95": 0.06584328358208953,
      "instances": 3.0,
      "accuracy": 0.0
    },
    "OR": {
      "precision": 0.0,
      "recall": 0.0,
      "f1": 0.0,
      "ap50": 0.0,
      "ap50_95": 0.0,
      "instances": 4.0,
      "accuracy": 0.0
    },
    "NOT": {
      "precision": 0.01935483870967742,
      "recall": 1.0,
      "f1": 0.0379746835443038,
      "ap50": 0.04639423076923077,
      "ap50_95": 0.02908260101699543,
      "instances": 3.0,
      "accuracy": 0.0
    },
    "NAND": {
      "precision": 0.0374331550802139,
      "recall": 1.0,
      "f1": 0.07216494845360824,
      "ap50": 0.2227566844919785,
      "ap50_95": 0.16394368474662585,
      "instances": 7.0,
      "accuracy": 0.0
    },
    "NOR": {
      "precision": 0.024193548387096774,
      "recall": 1.0,
      "f1": 0.047244094488188976,
      "ap50": 0.3055999999999999,
      "ap50_95": 0.10101999999999997,
      "instances": 3.0,
      "accuracy": 0.0
    },
    "XOR": {
      "precision": 0.019417475728155338,
      "recall": 1.0,
      "f1": 0.03809523809523809,
      "ap50": 0.04522727272727273,
      "ap50_95": 0.01666193181818182,
      "instances": 2.0,
      "accuracy": 0.0
    },
    "XNOR": {
      "precision": 0.035398230088495575,
      "recall": 1.0,
      "f1": 0.06837606837606837,
      "ap50": 0.11027450980392155,
      "ap50_95": 0.06790441176470588,
      "instances": 4.0,
      "accuracy": 0.0
    }
  },
  "gate": {
    "f1_threshold": 0.95,
    "accuracy_threshold": 0.95,
    "failing_classes": [
      "NMOS",
      "PMOS",
      "VDD",
      "GND",
      "INPUT_PORT",
      "OUTPUT_PORT",
      "JUNCTION",
      "AND",
      "OR",
      "NOT",
      "NAND",
      "NOR",
      "XOR",
      "XNOR"
    ],
    "passed": false
  },
  "class_names": [
    "NMOS",
    "PMOS",
    "VDD",
    "GND",
    "INPUT_PORT",
    "OUTPUT_PORT",
    "JUNCTION",
    "AND",
    "OR",
    "NOT",
    "NAND",
    "NOR",
    "XOR",
    "XNOR"
  ],
  "dataset": {
    "data": "~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/data/data.yaml",
    "train_images": 140,
    "val_images": 30,
    "test_images": 30,
    "real_oversample": 1
  },
  "settings": {
    "model": "yolov8n.pt",
    "epochs": 2,
    "imgsz": 320,
    "batch": 8,
    "device": "cpu",
    "workers": 8,
    "seed": 0,
    "lr0": 0.01
  },
  "environment": {
    "python": "3.14.6",
    "platform": "Linux-6.8.0-149-generic-x86_64-with-glibc2.35",
    "cpu_count": 12,
    "torch": "2.12.1+cu130",
    "ultralytics": "8.4.86",
    "cuda_devices": []
  },
  "train_seconds": 159.5,
  "weights": "~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke/best.pt",
  "onnx": "~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke/best.onnx",
  "ultralytics_run_dir": "~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/smoke/train"
}
Evidence: train.py dry-run for device 0,1,2,3 and device 0
== dry-run device 0,1,2,3
{
  "preset": "stage-a",
  "model": "yolov8s.pt",
  "device": {
    "spec": "0,1,2,3",
    "cpu": false,
    "world_size": 4,
    "ddp": true
  },
  "batch_total": 64,
  "batch_per_process": 16,
  "workers": 8,
  "epochs": 100,
  "imgsz": 960,
  "lr0": 0.01,
  "patience": 20,
  "real_train": [],
  "real_oversample": 1,
  "resume": null,
  "run_dir": "~/.no-mistakes/worktrees/d6f1543da1b7/01M7NJTQJYB57MKYJRZE5QSEM3/ml/experiments/run_20261118_0309",
  "dataset": {
    "data": "~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/data/data.yaml",
    "classes": 14,
    "eval_split": "test",
    "train_images": 140,
    "val_images": 30,
    "test_images": 30
  },
  "warnings": [
    "yolov8s.pt is a pretrained-weights name that ultralytics downloads on first use"
  ]
}
== dry-run device 0
{
  "preset": "stage-a",
  "model": "yolov8s.pt",
  "device": {
    "spec": "0",
    "cpu": false,
    "world_size": 1,
    "ddp": false
  },
  "batch_total": 16,
  "batch_per_process": 16,
  "workers": 8,
  "epochs": 100,
  "imgsz": 960,
  "lr0": 0.01,
  "patience": 20,
  "real_train": [],
  "real_oversample": 1,
  "resume": null,
  "run_dir": "~/.no-mistakes/worktrees/d6f1543da1b7/01M7NJTQJYB57MKYJRZE5QSEM3/ml/experiments/run_20261118_0309",
  "dataset": {
    "data": "~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/data/data.yaml",
    "classes": 14,
    "eval_split": "test",
    "train_images": 140,
    "val_images": 30,
    "test_images": 30
  },
  "warnings": [
    "yolov8s.pt is a pretrained-weights name that ultralytics downloads on first use"
  ]
}
Evidence: Kaggle script dry-run for device 0,1,2,3
{
  "preset": "stage-a",
  "model": "yolov8s.pt",
  "resume": null,
  "device_ids": [
    0,
    1,
    2,
    3
  ],
  "device": "0,1,2,3",
  "world_size": 4,
  "ddp": true,
  "batch_total": 64,
  "workers": 8,
  "epochs": 100,
  "imgsz": 960,
  "patience": 20,
  "lr0": 0.01,
  "lrf": 0.01,
  "warmup_epochs": 3.0,
  "close_mosaic": 10,
  "plots": true,
  "seed": 0,
  "real_train": [],
  "real_oversample": 1,
  "data_yaml": "~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/data/data.yaml",
  "out_dir": "~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/kout",
  "warnings": []
}
  • Evidence: Kaggle-layout smoke run log (local file: ~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/kaggle_smoke.log)
  • Evidence: Stage-B resume log (resumes from epoch 2) (local file: ~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/stageb_resume.log)
Evidence: Stage-B config.yaml after resume (real_oversample 4 kept)
preset: stage-b
model: ~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/stageb/train/weights/last.pt
data: ~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/data/data.yaml
project: ~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs
name: stageb
epochs: 4
imgsz: 320
batch: 16
device: cpu
world_size: 1
workers: 8
patience: 15
lr0: 0.002
lrf: 0.1
warmup_epochs: 1.0
close_mosaic: 5
plots: true
seed: 0
real_train:
- ~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/real
real_oversample: 4
resume: ~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/stageb/train/weights/last.pt
class_check: strict
install_weights: false
notes: ''
data_effective: ~/.no-mistakes/evidence/01M7NJTQJYB57MKYJRZE5QSEM3/w/runs/stageb/data_mixed.yaml
- Outcome: ⚠️ 1 info across 1 run (10m38s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

🔧 **Rebase** - 1 issue found → auto-fixed ✅
  • ⚠️ ml/pyproject.toml - merge conflict rebasing onto origin/main

🔧 Fix applied.
✅ Re-checked - no issues remain.

⚠️ **Review** - 1 info
  • ⚠️ ml/kaggle/train_kaggle.py:464 - Resuming a stage-B run silently drops real-image oversampling and rewrites the run's record. In ml/kaggle/train_kaggle.py, build_plan reuses saved preset, imgsz and data_yaml on --resume, but takes real_train and real_oversample only from the CLI. run() then calls prepare_data_yaml(...) with no real_train. That overwrites out/data.yaml, the file ultralytics stored in the checkpoint's args and re-reads on resume=True. Training therefore continues on the un-oversampled train split with no error. Sibling sites: ml/train.py resolve_config (around line 425) and train() (around line 615) also ignore saved real_train and real_oversample and rewrite config.yaml with real_train=[] and oversample 1. metrics.json then reports real_oversample: 1 for a run that trained with 4. Other settings are reused from the saved config but are likewise not restored: epochs in the Kaggle plan, and patience, lr0 and seed in both scripts. Fix: on resume, restore these from the saved config.yaml, or at least skip rewriting data.yaml and config.yaml for a resumed run.
  • ⚠️ ml/tests/test_train_harness.py:131 - test_no_hardcoded_cpu_in_train_calls only reads train.py and train_kaggle.py and counts the substring device=&#34;cpu&#34; and a format=&#34;onnx&#34; line. That violates the repo test-quality rule (source-text assertions). Matching text can sit in a comment or dead code, and a behavior-preserving refactor, such as moving the export device into a constant, breaks the test. It also proves nothing about runtime behavior. Replace it with a test that runs the real code path and checks the device value passed to ultralytics. For example, stub ultralytics.YOLO and assert that train() passes cfg.device.spec to model.train.
  • ℹ️ ml/kaggle/train_kaggle.py:568 - main() uses parse_known_args and discards the unknown arguments, so on a paid multi-GPU run a typo such as --real_train or --dataset_hint is silently ignored. The run would then start without oversampling and with the wrong dataset selection. The only arguments that need ignoring are the Jupyter kernel's -f &lt;file&gt;. Narrow the filter to -f and its value, and let argparse reject everything else.
  • ℹ️ ml/tests/test_train_harness.py:280 - The acceptance criterion says a 2-epoch CPU smoke run on 200 images must complete in CI-like conditions and produce metrics.json and an ONNX file. The only test that checks this is opt-in (DIGISIM_ML_SMOKE=1, skipped by default). It also downloads yolov8n.pt, so default pytest and CI never exercise the training, export and metrics path. Everything else in the harness is only dry-run or unit tested. This is acceptable if the author ran it manually, but the criterion is not enforced automatically.

🔧 Fix applied.
1 info still open:

  • ℹ️ ml/tests/test_train_harness.py:280 - The acceptance criterion says a 2-epoch CPU smoke run on 200 images must complete in CI-like conditions and produce metrics.json and an ONNX file. The only test that checks this is opt-in (DIGISIM_ML_SMOKE=1, skipped by default). It also downloads yolov8n.pt, so default pytest and CI never exercise the training, export and metrics path. Everything else in the harness is only dry-run or unit tested. This is acceptable if the author ran it manually, but the criterion is not enforced automatically.
⚠️ **Test** - 1 info
  • ℹ️ ml/train.py:644 - On --resume, batch and workers are not restored from the saved config.yaml. A stage-B run started with --batch 8 resumed with the preset default of 16, and config.yaml and metrics.json were rewritten with 16. Ultralytics does let batch, imgsz and device be overridden on resume, and batch is hardware-dependent, so this may be intended. It could OOM if someone resumes on a smaller GPU without passing --batch again.
  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
CPU smoke run: 2 epochs on 200 images produces best.pt, best.onnx and metrics.json ✅ pass live smoke_run.log, smoke_metrics.json; run dir contained best.pt, best.onnx, metrics.json
Dry-run with device 0,1,2,3 resolves to a 4-process DDP plan (train.py and the Kaggle script) without needing GPUs ✅ pass live dryrun_train.txt, kaggle_dryrun.txt (world_size 4, ddp true, batch 64)
Kaggle script reads a dataset from an input root and writes best.pt, ONNX and metrics.json ✅ pass live kaggle_smoke.log (rc=0; output folder had best.onnx, best.pt, metrics.json, config.yaml, data.yaml)
Adversarial: a mistyped Kaggle CLI argument (--real_train) is rejected instead of silently ignored ✅ pass live CLI output: 'unrecognized arguments: --real_train x'
Adversarial: stage-B resume after an interruption keeps real-image oversampling ✅ pass live stageb_resume.log ('Resuming ... from epoch 2 to 4'); train_mixed.txt checksum unchanged; config.yaml real_oversample 4; metrics.json dataset.real_oversample 4
Adversarial: real training images that overlap val/test are refused ✅ pass live stageb_run1.log: 'error: 30 real training image(s) are also in val/test'
Real multi-GPU DDP training on device 0,1,2,3 ⏸️ untested no This machine has no NVIDIA GPU (nvidia-smi is absent). Multi-GPU training needs a Kaggle GPU runtime, and no Kaggle credentials exist, so the dry-run flag is the agreed check.
  • python ml/make_smoke_dataset.py --out &lt;tmp&gt;/data --count 200 (200 synthetic images, 14 classes, split 140/30/30)
  • train.py --preset smoke --device cpu --class-check off on the 200-image set (real 2-epoch YOLOv8n CPU training, about 2m40s, rc=0)
  • train.py --preset stage-a --device 0,1,2,3 --dry-run and --device 0 --dry-run (resolved plan JSON, no torch import)
  • kaggle/train_kaggle.py --device 0,1,2,3 --dry-run, and with the typo --real_train x (argparse rejects it)
  • kaggle/train_kaggle.py --preset smoke --input-root &lt;fake /kaggle/input&gt; --device cpu --skip-install (discovers the dataset, writes best.pt, best.onnx, metrics.json)
  • Stage-B run with --real-train &lt;folder of real-style images&gt; --real-oversample 4: it stopped after epoch 1, then train.py --resume &lt;run dir&gt; ran with no other flags
  • Stage-B with the real folder pointing at the validation images (the leak guard)
  • uv run pytest ml/tests/test_train_harness.py -q: 31 passed, 1 skipped (the opt-in smoke test)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…e, ONNX export and metrics.json

- ml/train.py: --device (cpu|auto|0|0,1,2,3, DDP), --data, --imgsz, --model, --resume, --workers from CPU count; no hardcoded cpu
- smoke / stage-a (synthetic pretrain) / stage-b (mixed fine-tune with real oversampling) presets
- runs write best.pt, best.onnx, metrics.json (per-class P/R/F1/accuracy, gate verdict)
- --dry-run prints the resolved plan without importing torch
- ml/kaggle/train_kaggle.py: single-file Kaggle entry point
- ml/make_smoke_dataset.py + ml/tests: harness tests and opt-in 2-epoch CPU smoke run
@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
digisim Ready Ready Preview Nov 17, 2026 9:51pm UTC

@netlify

netlify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for digisim ready!

Name Link
🔨 Latest commit 0a76420
🔍 Latest deploy log https://app.netlify.com/projects/digisim/deploys/6afccc300d3200be04161f77
😎 Deploy Preview https://deploy-preview-28--digisim.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Mani212005
Mani212005 merged commit 15d7052 into main Nov 17, 2026
9 checks passed

This branch was successfully deployed

1 active deployment
Preview — 0a76420c Deployed Nov 17, 2026 by vercel[bot]
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.

1 participant