Skip to content

Pack DeepSeek V4.1 Metal candidate masks - #1383

Draft
forest1040 wants to merge 1 commit into
antirez:mainfrom
forest1040:deepseek-v41-packed-mask-main
Draft

forest1040 wants to merge 1 commit into
antirez:mainfrom
forest1040:deepseek-v41-packed-mask-main

Conversation

@forest1040

Copy link
Copy Markdown

Pack DeepSeek V4.1 Metal candidate masks into one bit per candidate block. The bit order matches the existing compact carry format, and carry operations can copy packed mask rows directly. The Metal score filter and candidate-list builder accept the packed representation. CUDA and ROCm continue to use the existing dense representation.

This addresses remaining mask storage in ds4's prefill path. The related llama.cpp change removes other graph intermediates. ds4 already filters scores in place and reuses a 32-row score tile.

Measurements

Mac Studio M3 Ultra 512 GiB and DeepSeek-V4.1-Flash-1017-IQ2_XXS-Q2_K-imatrix.gguf. The 128 Ki rows show the median of two runs on this branch with dense and packed masks. The 640 Ki row is one run per mode with a 32 Ki-token input. Memory is the static context-buffer plan reported by ds4-bench. The model mmap and OS page cache are separate.

Allocated context Input frontier Prefill dense → packed Decode dense → packed Static buffers dense → packed
128 Ki 32 Ki 810.93 → 813.46 tok/s 38.80 → 39.14 tok/s 9,248.00 → 8,751.94 MiB
128 Ki 64 Ki 776.66 → 778.73 tok/s 38.96 → 39.09 tok/s Same allocation
640 Ki 32 Ki 797.19 → 813.11 tok/s 38.40 → 38.29 tok/s 15,400.28 → 12,919.98 MiB

For a direct comparison, unmodified upstream b3f5018 ran at 812.19 and 777.00 prefill tok/s, and 39.05 and 38.95 decode tok/s, at the two 128 Ki frontiers. Each frontier generates 16 tokens. The 64 Ki prefill figure measures the second 32 Ki tokens.

Verification and reproduction

  • The Metal tests compare filtered scores and ordered candidate IDs, including partial blocks, strided masks, and tied scores.
  • All logits matched bitwise at positions 16,384, 16,385, 32,768, and 32,769. The graph test also passed with compact carry and batch top-k disabled.
  • The CPU object built successfully. GPU execution tests ran on Metal.
make ds4-bench tests/test_deepseek41_metal tests/test_deepseek41_graph
./tests/test_deepseek41_metal
./tests/test_deepseek41_graph "$MODEL" --candidate-mask-parity
DS4_METAL_DISABLE_V41_COMPACT_CARRY=1 DS4_METAL_DISABLE_V41_BATCH_TOPK=1 \
  ./tests/test_deepseek41_graph "$MODEL" --candidate-mask-parity 16432

DS4_METAL_DISABLE_V41_PACKED_CANDIDATE_MASK=1 \
  ./ds4-bench --metal -m "$MODEL" --prompt-file speed-bench/promessi_sposi.txt \
  --ctx-start 32768 --ctx-max 65536 --step-incr 32768 --ctx-alloc 131072 --gen-tokens 16 --csv /tmp/dense.csv
./ds4-bench --metal -m "$MODEL" --prompt-file speed-bench/promessi_sposi.txt \
  --ctx-start 32768 --ctx-max 65536 --step-incr 32768 --ctx-alloc 131072 --gen-tokens 16 --csv /tmp/packed.csv

Use one bit per candidate block and copy packed carry rows directly. Preserve candidate IDs and logits on M3 Ultra while reducing the tracked Metal peak by 496 MiB at 128 Ki context and 2.42 GiB at 640 Ki allocated context.
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