MCPcopy Create free account
hub / github.com/MLSysU/TD-Pipe / _process_sequence_group_outputs

Method _process_sequence_group_outputs

TD_Pipe/engine/llm_engine.py:435–604  ·  view source on GitHub ↗
(self, seq_group: SequenceGroup,
                                        outputs: SequenceGroupOutput)

Source from the content-addressed store, hash-verified

433 return current_worst_score >= highest_attainable_score
434
435 def _process_sequence_group_outputs(self, seq_group: SequenceGroup,
436 outputs: SequenceGroupOutput) -> None:
437 # Process prompt logprobs
438 prompt_logprobs = outputs.prompt_logprobs
439 if prompt_logprobs is not None:
440 seq_group.prompt_logprobs = prompt_logprobs
441
442 # Process samples
443 samples = outputs.samples
444 parent_seqs = seq_group.get_seqs(status=SequenceStatus.READY)
445 existing_finished_seqs = seq_group.get_finished_seqs()
446 parent_child_dict = {
447 parent_seq.seq_id: []
448 for parent_seq in parent_seqs
449 }
450 for sample in samples:
451 parent_child_dict[sample.parent_seq_id].append(sample)
452 # List of (child, parent)
453 child_seqs: List[Tuple[Sequence, Sequence]] = []
454
455 # Process the child samples for each parent sequence
456 for parent in parent_seqs:
457 child_samples: List[SequenceOutput] = parent_child_dict[
458 parent.seq_id]
459 if len(child_samples) == 0:
460 # This parent sequence has no children samples. Remove
461 # the parent sequence from the sequence group since it will
462 # not be used in the future iterations.
463 parent.status = SequenceStatus.FINISHED_ABORTED
464 seq_group.remove(parent.seq_id)
465 self.scheduler.free_seq(parent)
466 continue
467 # Fork the parent sequence if there are multiple child samples.
468 for child_sample in child_samples[:-1]:
469 new_child_seq_id = next(self.seq_counter)
470 child = parent.fork(new_child_seq_id)
471 child.append_token_id(child_sample.output_token,
472 child_sample.logprobs)
473 child_seqs.append((child, parent))
474 # Continue the parent sequence for the last child sample.
475 # We reuse the parent sequence here to reduce redundant memory
476 # copies, especially when using non-beam search sampling methods.
477 last_child_sample = child_samples[-1]
478 parent.append_token_id(last_child_sample.output_token,
479 last_child_sample.logprobs)
480 child_seqs.append((parent, parent))
481
482 for seq, _ in child_seqs:
483 self._decode_sequence(seq, seq_group.sampling_params)
484 self._check_stop(seq, seq_group.sampling_params)
485
486 # Non-beam search case
487 if not seq_group.sampling_params.use_beam_search:
488 # For newly created child sequences, add them to the sequence group
489 # and fork them in block manager if they are not finished.
490 for seq, parent in child_seqs:
491 if seq is not parent:
492 seq_group.add(seq)

Callers 1

Calls 13

_decode_sequenceMethod · 0.95
_check_stopMethod · 0.95
get_seqsMethod · 0.80
get_finished_seqsMethod · 0.80
removeMethod · 0.80
free_seqMethod · 0.80
addMethod · 0.80
fork_seqMethod · 0.80
get_beam_search_scoreMethod · 0.80
forkMethod · 0.45
append_token_idMethod · 0.45

Tested by

no test coverage detected