fix(generate): avoid None entries in merged logits_processors#1230
fix(generate): avoid None entries in merged logits_processors#1230BLuchterhand wants to merge 1 commit into
Conversation
b279bd1 to
b58f987
Compare
PromptProcessingBatch.extend filled missing per-slot logits_processors with [None] when either side lacked configured processors. Merging an unconfigured batch with a processor-equipped batch then produced a list shaped like [None, ..., [fn], ...]. GenerationBatch._step at line 1346 iterates self.logits_processors[e] under the any() guard at line 1337, which raises TypeError on the None slots. Fill with [[]] instead. Matches the existing pattern at line 1120 (filter() restoring [[]] * len(keep)) and the per-slot type List[Callable]. Reproduce: construct two PromptProcessingBatch instances, one without processors and one with, then call extend; the merged self.logits_processors contains None entries. New unit test covers this shape directly.
b58f987 to
423301b
Compare
|
+1 — independent production hit, batched-inference server, mlx-lm 0.31.3. Our workload mixes grammar-mode requests (RAG hybrid search using Live traceback at The diagnosis matches yours exactly. The supervisor in our setup catches the crash via We're applying your diff to our local Validated locally: a regression probe that fires a long plain request followed by a grammar request ~300 ms later (so the grammar request Related: #1225 lands the symmetric fix in |
|
Thanks! This seems to be duplicated in https://github.com/ml-explore/mlx-lm/pull/1225/changes |
…t per-slot logits_processors extend() fills missing per-slot logits_processors with [None] * N. Merging an unconfigured batch with a processor-equipped batch produces a mixed list ([None, ..., [fn], ...]); GenerationBatch._step then iterates self.logits_processors[e] under the any() guard and crashes with TypeError: 'NoneType' object is not iterable. Per-slot type is List[Callable], so the absent-value sentinel is [] — matching the existing [[]] * len(keep) in PromptProcessingBatch.filter. samplers keep the None sentinel (consumed as `self.samplers[e] or self.fallback_sampler`, type Optional[Callable]). Fix and regression test carried over from ml-explore#1230 (closed as duplicate of this PR; the two changes are companions in the same file — filter here, extend there). Co-authored-by: BLuchterhand <benlucht8@gmail.com>
Bug
PromptProcessingBatch.extendfilled missing per-slotlogits_processorswith[None] * N. Merging an unconfigured batch with a processor-equipped batch produced a list shaped[None, ..., [fn], ...].GenerationBatch._step(line 1346) iteratesself.logits_processors[e]under theany()guard at line 1337, which raisesTypeError: 'NoneType' object is not iterableon theNoneslots.Reproduce
Fix
Per-slot type is
List[Callable], so the absent-value sentinel should be[], notNone. Matches the existing[[]] * len(keep)at line 1120 (PromptProcessingBatch.filter).Test
test_prompt_processing_batch_extend_mixes_logits_processorsintests/test_generate.py. Asserts noNoneentries remain in the merged list. Fails onmain(AssertionError: None is not an instance of <class 'list'>), passes with the fix.Related
#1225 fixes the symmetric stale-length bug in
GenerationBatch.filter. This is situated in a different code path so both can land independently.Traceback (production hit)