Optimize ANE training with weights-as-tensors, add inference and benc… - #18
Optimize ANE training with weights-as-tensors, add inference and benc…#18andyhyh wants to merge 3 commits into
Conversation
- Implement modular ANE-MIL layer library (Linear, Conv2D, Softmax, LayerNorm, etc.) - Add Sequential model container with automated activation surface chaining (ping-ponging) - Implement optimized 'Weights-as-Tensors' pattern across all SDK layers for zero-recompile weight updates - Add comprehensive automated regression testing suite (regression_test.py) - Standardize verification for legacy Transformer training and new modular SDK components - Update README.md and roadmap to reflect SDK capabilities and usage instructions - Refactor hardcoded paths and unify checkpoint naming conventions for stability
|
Great work! I was also fiddling with weights as tensors alternative and it seems to work with a slight increase in per step time. The static approach had the option of fusing together ops in forward and backward passes, you reduce ANE time with that but compilation time then becomes the overhead. It'll be interesting to see which approach scales better for speed vs flexibility |
Thanks! We (myself with Gemini 3 Flash) started looking how to generalise this more into an ANE SDK with a python interface as a side hustle. We had been doing this on a macbook air with M2. I'm going to try on my m4 air and see how it changes. |
|
Running into regression issues on M4 air causing MacOS to crash. Will regression more throughly before opening new PR. |
ane_lint.py encodes Orion's constraint catalog (arXiv:2603.06728). compile() now rejects known-bad MIL with 422 BEFORE spending a compile: concat (#1), gelu (maderix#10), conv bias= (maderix#13), non-uniform multi-output sizes (#2), non-uniform multi-input alloc (maderix#18), and sub-~49KB IOSurfaces (maderix#4). Plus ANE017 (prefer conv1x1) and fusion-depth advisories as info. New POST /raw/lint validates without compiling; compile surfaces non-error findings as warnings. Notably ANE004 explains the matmul MIL's 0x1d: its 21.6 KB input is under the ~49 KB IOSurface floor, so it now fails fast with a clear message instead of at eval. 8 new tests (21 total). Co-Authored-By: Claude <noreply@anthropic.com>
…uristics ane_mil.parse() extracts funcs (signature inputs/outputs) and statements (op, args, attrs, output dtype/shape) via balanced bracket matching; ane_mil.validate() checks the Orion catalog precisely — banned ops (concat/gelu) by op-name, conv bias=, matmul transpose-const (maderix#12), 32K-channel conv (maderix#16), output liveness (maderix#14), multi-output uniform (#2) + alphabetical binding (maderix#3), multi-input alphabetical (maderix#19). ane_lint.lint_mil uses the parser as primary and falls back to the regex checks when a program won't parse; size checks (maderix#4 min / maderix#18 input-uniform) and perf advisories always run. End-to-end via /raw/lint (func-wrapped gelu -> ANE010, relu -> ok). 71 tests (9 new parser tests). Co-Authored-By: Claude <noreply@anthropic.com>
PR Description: Scalable ANE Training with Weights-as-Tensors & Inference Utilities
Overview
This PR significantly optimizes the ANE training pipeline to enable scalable, long-running training sessions. The core change is a transition from "Baked-Weight" kernels to a "Weights-as-Tensors" architecture, which allows for dynamic weight updates without hitting the OS-enforced ANE compile limits.
Key Changes
1. Zero-Recompile Architecture (Weights-as-Tensors)
tensor<fp16, [dim, dim]>inputs instories_mil.h.io_write_fp16_t).exec()restarts required for long runs.2. High-Performance ANE Benchmarking
benchmark_ane.mto measure native hardware performance.3. End-to-End Workflow Utilities
sample.py: Standalone NumPy-based inference script with BPE tokenizer support to verify model quality.tokenize_text.py: General-purpose data preparation tool to convert any text file into the binary format required by the trainer..gitignore: Added to keep the repository clean of binaries and large datasets.Performance Comparison
How to Test
make train_large && ./train_largeto observe stable, high-speed training.make benchmark_ane && ./benchmark_anefor native hardware metrics.python3 sample.py --prompt "Once upon a time"to generate text from a trained checkpoint.