Skip to content

fix(inference): handle None top_k/top_p defaults in sample_from_logits#351

Open
dvirarad wants to merge 1 commit into
shiyu-coder:masterfrom
dvirarad:fix/sample-from-logits-none-topk-topp
Open

fix(inference): handle None top_k/top_p defaults in sample_from_logits#351
dvirarad wants to merge 1 commit into
shiyu-coder:masterfrom
dvirarad:fix/sample-from-logits-none-topk-topp

Conversation

@dvirarad

Copy link
Copy Markdown

What

sample_from_logits declares top_k=None / top_p=None defaults, but its guard evaluates top_k > 0 or top_p < 1.0 whenever either value is non-None. Supplying only one filter — e.g. sample_from_logits(logits, top_p=0.9) — hits None > 0 and raises TypeError: '>' not supported between instances of 'NoneType' and 'int'. A None could likewise be forwarded into top_k_top_p_filtering, which does the same comparison.

Fix

Normalize an omitted parameter to its neutral value (top_k=0, top_p=1.0) before comparing. No behavior change for existing callers (auto_regressive_inference and KronosPredictor.predict always pass explicit numbers); this only fixes the crash when one filter is left at its default.

Testing

Verified the guard against {}, top_p=0.9, top_k=5, top_k=0,top_p=0.99, top_k=0,top_p=0.9: old code crashed only on the top_p-only case; new code matches old behavior everywhere else. python -m py_compile model/kronos.py passes.

`sample_from_logits` declares `top_k=None` and `top_p=None` defaults, but
its guard evaluated `top_k > 0 or top_p < 1.0` whenever either value was
not None. Passing only one filter (e.g. `sample_from_logits(logits,
top_p=0.9)`) therefore raised `TypeError: '>' not supported between
instances of 'NoneType' and 'int'`, and a None value could also be passed
down to `top_k_top_p_filtering`, which performs the same comparison.

Normalize the unset parameter to its neutral default (top_k=0, top_p=1.0)
before the comparison. Behavior is unchanged for all existing call sites,
which always pass explicit numeric values.
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