feat: add qwen3 tts topk gumbel sampler - #64
Open
l-wave wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a Qwen3-TTS oriented short-vocab fused sampler operator,
qwen3_tts_topk_gumbel_sample, for TTS/code-token sampling workloads.The new op handles standalone logits and pre-generated uniform noise tensors:
logits:[batch_size, vocab_size]noise:[batch_size, vocab_size]float32vocab_size <= 20481 <= topk <= 64vocab_size=2048,topk=50It returns sampled token ids:
[batch_size, 1]int64It exposes:
hpc.qwen3_tts_topk_gumbel_sampletorch.ops.hpc.qwen3_tts_topk_gumbel_samplesrc/sampler/qwen3_tts_topk_gumbel_sample.cutests/test_sampler.pyMotivation
Existing hpc-ops sampler kernels are designed for more general large-vocab sampling flows. The generic
fused_samplersupports features such as repetition penalty, temperature, softmax policy, top-k, top-p, Gumbel-max sampling, and penalty-mask writeback. It is a feature-rich large-vocab path, but it is not the most direct fit for Qwen3-TTS code-token sampling.The Qwen3-TTS code predictor path uses a much narrower sampling pattern:
For short TTS vocabularies such as
V <= 2048, this PyTorch expression introduces multiple CUDA launches and intermediate tensors. Reusing the generic sampler also brings machinery that this path does not need, such as large-vocab multi-block top-k, top-p, softmax policy, repetition penalty, and penalty-mask writeback.This PR adds a dedicated short-vocab fused sampler for this TTS path.
What changed
This PR adds a fused CUDA kernel for short-vocab TTS top-k Gumbel sampling:
2048topkup to64topk=50pathfused_samplerThe PR also adds minimal-build support used by focused operator validation:
HPC_OPS_IMPORT_MODULES=samplerimports only sampler Python APIsversion/built_jsonops are tolerated only in explicit minimal-import modebuild/lib.*and in-place_C.abi3.soDifference from existing sampler
The existing
fused_sampleris a general sampler for large-vocab decoding. It supports a broad feature set:float32/bfloat16logits120832The new
qwen3_tts_topk_gumbel_sampleis intentionally narrower:float32logitsV <= 2048topk <= 64This specialization lets the kernel avoid generic large-vocab sampler overhead and focus on the Qwen3-TTS code-token hot path.
Test coverage
Correctness is covered with a general TTS short-vocab matrix:
64,128,256,512,1024,1536,20481,4,16,32,50,641,4,8,16,32,64inv_temperaturevalues42It also covers error and boundary cases:
topkvocab_size > 2048Correctness command:
HPC_OPS_IMPORT_MODULES=sampler pytest tests/test_sampler.py -q -k "qwen3_tts_topk_gumbel_sample and not benchmark"Current result:
Benchmark
Environment:
Benchmark result summary, excluding the removed
topk=1micro-case:Across the representative short-vocab TTS matrix, the fused op is faster than the PyTorch reference, with around
1.68x–6.24xspeedup. For the production Qwen3-TTS settingV=2048, topk=50, the fused op is stable around~20usand about3.0xfaster than the PyTorch reference acrossB=1/8/32.Notes
This operator is intentionally narrower than a fully generic sampler. It currently targets:
float32logitsvocab_size <= 2048topk <= 64topk=50It does not replace the existing generic
fused_sampler; it complements it with a specialized fast path for Qwen3-TTS short-vocab sampling.