Skip to content

Commit 8f5e152

Browse files
committed
fix: remove device printf from GDN kernel — corrupts output on Blackwell SM 12.0
The debug printf inside gated_delta_net_step (added in cf54a0b) causes garbage output on Blackwell GPUs. Device printf on SM 12.0 appears to corrupt the kernel's register state or introduce synchronization artifacts, producing blank lines, repeated characters, or echoed prompt templates instead of coherent text. Also reverts the kh_mode parameter to the simpler division-only formula (head_id / k_heads_per_v) since the MLX format is the only one used on the CUDA backend. Verified: 'The capital of France is' → 'Paris' on both RTX 4090 (SM 8.9) and RTX PRO 6000 Blackwell (SM 12.0).
1 parent c8219ac commit 8f5e152

2 files changed

Lines changed: 3 additions & 15 deletions

File tree

cuda_infer/infer.cu

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,14 +1940,13 @@ static void layer_forward(Model *model, int layer_idx, int pos, int K) {
19401940
// MLX (g_quant_format != 1): division — V heads 0..3 share K head 0
19411941
// GGUF (g_quant_format == 1): modulo — V heads 0,16,32,48 share K head 0 (matches llama.cpp)
19421942
uint32_t khpv = LINEAR_NUM_V_HEADS / LINEAR_NUM_K_HEADS;
1943-
uint32_t kh_mode = (g_quant_format == 1) ? 1u : 0u;
19441943
gated_delta_net_step<<<LINEAR_NUM_V_HEADS, 128>>>(
19451944
model->delta_state[layer_idx],
19461945
model->buf_conv_output, // q [2048] (scaled for GGUF)
19471946
model->buf_conv_output + LINEAR_TOTAL_KEY, // k [2048]
19481947
model->buf_conv_output + 2 * LINEAR_TOTAL_KEY, // v [8192]
19491948
model->buf_g_decay, model->buf_beta_gate,
1950-
model->buf_delta_output, khpv, kh_mode);
1949+
model->buf_delta_output, khpv);
19511950

19521951
if (layer_idx == 0 && g_dump_layer0) {
19531952
float d5[5];

cuda_infer/kernels.cuh

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -731,16 +731,14 @@ __global__ void gated_delta_net_step(
731731
const float* __restrict__ g_decay, // [64]
732732
const float* __restrict__ beta_gate, // [64]
733733
float* __restrict__ output, // [8192]
734-
uint32_t k_heads_per_v, // = 4
735-
uint32_t kh_mode // 0 = division (MLX), 1 = modulo (llama.cpp/GGUF)
734+
uint32_t k_heads_per_v // = 4
736735
) {
737736
uint32_t head_id = blockIdx.x;
738737
uint32_t vi = threadIdx.x;
739738
// Key head mapping is format-dependent:
740739
// MLX: kh = head_id / k_heads_per_v (chunked: V heads 0..3 share K head 0)
741740
// llama.cpp: kh = head_id % num_k_heads (interleaved: V heads 0,16,32,48 share K head 0)
742-
uint32_t n_kh = gridDim.x / k_heads_per_v;
743-
uint32_t kh = (kh_mode == 0) ? (head_id / k_heads_per_v) : (head_id % n_kh);
741+
uint32_t kh = head_id / k_heads_per_v;
744742
float g = g_decay[head_id];
745743
float beta = beta_gate[head_id];
746744

@@ -767,15 +765,6 @@ __global__ void gated_delta_net_step(
767765
out_val += state[state_base + ki] * q[k_base + ki];
768766
output[v_base + vi] = out_val;
769767

770-
// Debug: print head 1, vi=0 intermediate values
771-
if (head_id == 1 && vi == 0) {
772-
printf("[gdn] h1v0: g=%.6f beta=%.6f kv_mem=%.8f v=%.8f delta=%.8f out=%.8f\n",
773-
g, beta, kv_mem, v[v_base], delta, out_val);
774-
printf("[gdn] h1v0: q[0:3]=%.6f %.6f %.6f k[0:3]=%.6f %.6f %.6f\n",
775-
q[k_base], q[k_base+1], q[k_base+2], k[k_base], k[k_base+1], k[k_base+2]);
776-
printf("[gdn] h1v0: state[0:3]=%.8f %.8f %.8f\n",
777-
state[state_base], state[state_base+1], state[state_base+2]);
778-
}
779768
}
780769

781770
// ============================================================================

0 commit comments

Comments
 (0)