apple / apple/coreai-torch

Grouped LUT convolution returns wrong per-group scaled values on ANE

Open
#93 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
152
Forks
45
Avg merge
1d 7m
Merged PRs (30d)
12

Description

## Observed

A `[64, 64, 1, 1]` convolution with signed-INT4 LUT weights and two K32 scales per output channel returns **1921 incorrect values out of 4096** on the ANE-preferred Core AI path. Relative L2 is **0.450247**. Splitting it into two K32 convolutions with per-output scales gives the expected output.

The input is a 64-channel identity matrix, with an exact input QDQ round trip. Weight scales have shape `[64, 2, 1, 1]`: alternating rows use `(0.125, 0.25)` and `(0.25, 0.125)`. Expected output is the INT4 weights multiplied by the corresponding K-group scales.

The native output matches this separately generated error model exactly: flatten the scale array and use its first 64 entries as one scale per output channel. The split output rejects that model:

| Case | Mismatches vs intended output | Mismatches vs flattened-scale prediction |
|---|---:|---:|
| `coreai-group-native64` | 1921 | 0 |
| `coreai-group-split32` | 0 | 1921 |

The saved asset audit confirms the four-bit indices, LUT, scale values and operand connections. Both cases show ANE participation in all four control windows. The scale-indexing match describes the observed output; it does not identify the internal compiler or runtime stage responsible.

## Environment

Apple M5 Pro, 48 GiB; macOS 27.0 (26A428); Xcode 27.0 (27A266a), SDK 27.0; Python 3.12.14, torch 2.11.0, coreai-torch 0.4.1, coreai-core 1.0.0b2. This report covers that recorded run; this probe has not been rerun with coreai-torch 0.4.2 on the same environment.

## Reproduction and records

The [archived reproducer](https://github.com/cadamcat/llms-on-apple-neural-engine/tree/ba79d22a0df214e3dcb9a1e9baeff02caaa137d1/findings/coreai-flattened-scale/repro) contains the original exporter and Swift host, synthetic inputs and all eight recorded outputs. The source hashes match the [published run](https://github.com/cadamcat/llms-on-apple-neural-engine/blob/cce9b49dcd5ad49070c1b9dab09b64e22e40042a/results/fresh/smoke.json), which also contains the asset audits and placement records.

Verify the recorded arrays offline, then optionally export and run the two cases on a Mac with the Core AI macOS 27 SDK/runtime:

```sh
git clone https://github.com/cadamcat/llms-on-apple-neural-engine.git
cd llms-on-apple-neural-engine
git checkout ba79d22a0df214e3dcb9a1e9baeff02caaa137d1
cd findings/coreai-flattened-scale/repro
uv venv --python 3.12 .venv
uv pip install --python .venv/bin/python numpy==2.3.5
.venv/bin/python verify.py
uv pip install --python .venv/bin/python -r requirements-device.txt
.venv/bin/python run_device.py --output run-01
```

The packaging helpers are new and verified offline; the small device runner has not been executed. It requests `.neuralEngine` and reports numerical differences, without collecting new placement logs.

Is this grouped-scale representation supported by Core AI, and should this output discrepancy be tracked in the converter or through Apple Feedback for the compiler/runtime?

Contributor guide

Open the contributing guide

Research direction

Start with findings/coreai-flattened-scale/repro/verify.py and the archived recorded outputs to confirm the grouped and split cases offline. If device access is available, run run_device.py with the documented environment and compare its results with the records. Done means establishing whether grouped scales are supported and whether the discrepancy belongs in conversion or Apple’s compiler/runtime feedback.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.