Skip to content

fix(interface): reject out-of-range topk before allocating outputs - #24

Open
Afloat16 wants to merge 1 commit into
deepseek-ai:mainfrom
Afloat16:fix/validate-topk-before-allocation
Open

Afloat16 wants to merge 1 commit into
deepseek-ai:mainfrom
Afloat16:fix/validate-topk-before-allocation

Conversation

@Afloat16

@Afloat16 Afloat16 commented Oct 1, 2026

Copy link
Copy Markdown

The native binding requires topk in [1, 4096], but the Python wrapper allocates output tensors before reaching that check. An invalid large value can therefore trigger an unnecessary allocation or an allocation error.

Reject out-of-range topk before allocating outputs. Values above the vocabulary length remain supported within the existing limit.

Validation:

  • 8 CPU wrapper tests pass; 5 fail on the unmodified source.
  • Tests also pass under python -O and python -OO.
  • Host pytest execution, test lint, Python compilation and git diff --check pass.

This only covers top-k bounds; #15 handles the separate begin/hint/output-dtype checks. Native CUDA/NPU kernels were not executed.

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