Commit Graph

27 Commits

Author SHA1 Message Date
Jourloy
847bd59c25 fix: use SDPA for dense attention on macOS 2026-07-17 09:44:06 +03:00
Jourloy
1488ba1505 fix: distinguish requested and safety decimation 2026-07-17 09:27:47 +03:00
Jourloy
83cf977a8f test: probe production split-k Metal kernel 2026-07-17 09:27:07 +03:00
Jourloy
b50b5c4fc5 fix: retry Metal build with ABI fallback 2026-07-17 09:26:00 +03:00
Jourloy
2b7f47fc87 fix: cache only pinned runtime weights 2026-07-17 09:24:41 +03:00
Jourloy
f59e6e5981 feat: add native Apple Silicon asset pipeline 2026-07-17 09:21:34 +03:00
Pedro Augusto
9c34570ffc deps: pin torch>=2.11.0 in requirements_macos.txt
The mtlgemm Metal extension's metal_context.mm calls
at::mps::dispatch_sync_with_rethrow, which was added to that namespace
in PyTorch 2.11.0 (pytorch/pytorch#167445, merged 2025-11-11). Earlier
stable releases (2.6 – 2.10) only expose it under at::native::mps::,
so installing mtlgemm against them fails the C++ extension build.

torchvision pinned to >=0.26.0 (matches torch 2.11) to keep the
torch/torchvision wheel pair ABI-compatible on resolution.
2026-07-17 07:51:05 +03:00
Pedro Augusto
f3177cd807 sparse/config: default ATTN to flex_gemm_sparse_attn on Darwin when flex_gemm probe passes
The flex_gemm_sparse_attn backend is now flash-attention-v2 with
simdgroup_matrix_multiply_accumulate for Q@K^T and P@V plus simd-shuffle
softmax row reductions, and wins 5–15× over SDPA-padded-CPU-bounce at
every measured shape including max_seqlen=2048. Production decoder block
on M3 Max: 5.04× wall-clock vs all-SDPA-padded baseline (3.49 ms vs
17.57 ms), entirely from this change being the default.

The existing __flex_gemm_works_on_mps() probe covers the same package
the attention path lives in, so the gate is identical: if conv probe
passes, set both CONV='flex_gemm' and ATTN='flex_gemm_sparse_attn'.
SPARSE_ATTN_BACKEND= (or ATTN_BACKEND=) env override is unchanged.

Also fix benchmarks/e2e_decoder.py to inject the repo root into
sys.path so it runs as `python benchmarks/e2e_decoder.py` from any cwd.
2026-07-17 07:51:05 +03:00
Pedro Augusto
cf886fd00e benchmarks/e2e_decoder: shell-conv + attention block micro-bench
End-to-end micro-bench for the production decoder block at res=32 ch=64
with seqlens=[256, 192, 128, 64]. Three stages reported (convs-only /
attn-only / combined block) at fp16, vs the all-SDPA-padded baseline.
Used to track the cumulative effect of the mtlgemm flash-attention-v2
fwd + bwd work on the actual decoder hot path.
2026-07-17 07:51:05 +03:00
Pedro Augusto
2b33c15277 sparse/attention: drop FUSED_ATTN_MAX_SEQLEN threshold to match CUDA-path precedent
The 256-cap inside the flex_gemm_sparse_attn branch was a hold-over from
the early naive Metal kernel (round 3). The current backend is flash-
attention-v2 with simdgroup matmul + simd-shuffle softmax row reductions
and wins at every measured shape including max_seqlen=2048. The CUDA
backends above (xformers / flash_attn / flash_attn_3) never fork on
max_seqlen — match that precedent.

Safety-valve preserved as FLEX_GEMM_ATTN_MAX_SEQLEN=N env var: when set,
falls back to SDPA-padded above the cap. Useful only on PyTorch builds
where the Accelerate-SDPA-CPU-bounce happens to win at a specific shape
(measured crossover sits beyond 768 on fp32, higher on fp16).
2026-07-17 07:51:05 +03:00
Pedro Augusto
369cb6c6fe sparse/norm: CPU-staged zeros_like workaround for MPS
SparseGroupNorm / SparseLayerNorm used torch.zeros_like which fails with
"DispatchStub: missing kernel for mps" on PyTorch builds compiled with
both CUDA and MPS backends (the user's local build hit this). Added a
_zeros_like_safe helper that builds zeros on CPU and transfers when the
reference tensor is on MPS; Apple Silicon unified memory makes the
transfer metadata-only, so the overhead vs a working MPS zeros kernel
is negligible. On CPU, behaves identically to torch.zeros_like.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-07-17 07:51:05 +03:00
Pedro Augusto
c869eb995a sparse/attention: add 'flex_gemm_sparse_attn' backend option
Wires the new mtlgemm fused sparse attention kernel through the ATTN
backend selector. Dispatches to the fused Metal kernel when
max(max_q, max_kv) <= 256 (where the naive per-thread-serial-KV kernel
beats SDPA-padded on M3 Max), and falls through to an inline SDPA-padded
path for larger max_seqlen. Opt in via ATTN_BACKEND=flex_gemm_sparse_attn
or SPARSE_ATTN_BACKEND=flex_gemm_sparse_attn. Default on Darwin stays
'sdpa' — the threshold-based fallback doesn't yet prove a universal
win across the pipeline's attention shape distribution.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-07-17 07:51:05 +03:00
Pedro Augusto
71f071fc76 sparse/config: probe flex_gemm masked path too, not just dense
The original probe only exercised Algorithm.IMPLICIT_GEMM. A stale install
where dense works but the masked cache/dispatch path is broken (e.g. the
pre-round-2 aliased-to-dense fallback) would select flex_gemm and crash at
the first MASKED_IMPLICIT_GEMM call inside the decoder. Probe both.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-07-17 07:51:05 +03:00
Pedro Augusto
2780bc459a sparse/config: probe flex_gemm on MPS, soft-fall-back to pytorch backend
The default Darwin path used to be a try/except ImportError, which only
catches build failures. With the mtlgemm round 1 fixes shipped, the more
common failure mode for end users will be running an *older* mtlgemm that
still returns CPU tensors from MPS calls — that doesn't fail import, it
fails with a cryptic LayerNorm crash inside the model on the first conv.

The new probe runs a tiny SparseConv3d on MPS and checks the output
device. If anything breaks (import, build, dispatch, return-device), fall
back to the pure-PyTorch backend rather than crashing inside the model.

Tensors in the probe are built on CPU then moved to MPS because some
PyTorch builds lack int/fp16 torch.zeros kernels on MPS — that's a
PyTorch issue, separate from anything we control here.

Plus: end-to-end smoke test (test_flex_gemm_integration.py) that
exercises both Algorithm.IMPLICIT_GEMM and Algorithm.MASKED_IMPLICIT_GEMM
through a real SparseConv3d → F.layer_norm chain on MPS. Confirms both
algorithms return MPS tensors of the right dtype and produce equivalent
output.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-07-17 07:51:05 +03:00
Pedro Augusto
d15e6de829 inline env defaults in api_server, remove start script, drop intermediate mx.eval syncs 2026-07-17 07:51:05 +03:00
Pedro Augusto
9cd27537d9 add mlx backend for apple silicon with metal gpu acceleration 2026-07-17 07:51:05 +03:00
Jianfeng Xiang
75fbf01830
Merge pull request #166 from microsoft/copilot/fix-failing-github-actions-job
Fix CodeQL c-cpp analysis: switch build-mode from autobuild to none
2026-06-05 13:19:14 +08:00
copilot-swe-agent[bot]
173e6ee351
Fix CodeQL c-cpp analysis: change build-mode from autobuild to none 2026-06-05 05:15:34 +00:00
copilot-swe-agent[bot]
a908f0e246
Initial plan 2026-06-05 05:13:09 +00:00
Jianfeng Xiang
d3b9d483e9
Add CodeQL analysis workflow configuration
This workflow file sets up CodeQL analysis for multiple languages, including C/C++ and Python, with scheduled runs and pull request checks.
2026-06-05 13:03:23 +08:00
JeffreyXiang
5565d240c4 Release Training Code 2026-01-10 09:47:30 +00:00
JeffreyXiang
903bfcf51a update texturing pipeline 2025-12-23 12:57:08 +00:00
JeffreyXiang
1762f493fe update paper link 2025-12-17 02:27:18 +00:00
JeffreyXiang
10b3de9e6f Fix website url 2025-12-16 20:13:17 +00:00
JeffreyXiang
4f15c72a17 Add demo link 2025-12-16 19:15:03 +00:00
JeffreyXiang
de38fdd408 Init Release 2025-12-16 19:00:42 +00:00
microsoft-github-operations[bot]
7f9ccee603
Initial commit 2025-11-26 10:04:36 +00:00