()
| 55 | output_tensors_cpu: ModelOutputTensors | None = None |
| 56 | |
| 57 | def preprocess(): |
| 58 | command: CommandFromManager = state.input_q.get() |
| 59 | |
| 60 | match command: |
| 61 | case ModelInput(): |
| 62 | inp = command |
| 63 | case NoMoreInputs(): |
| 64 | return None |
| 65 | case _: |
| 66 | raise ValueError(f"Unknown command: {type(command)}") |
| 67 | |
| 68 | batch_indices = torch.tensor( |
| 69 | inp.batch_indices, |
| 70 | dtype=torch.long, |
| 71 | ) |
| 72 | |
| 73 | num_total_padding, num_lm_head_padding = model_runner.calc_padding( |
| 74 | num_prefill_tokens=inp.num_prefill_tokens(), |
| 75 | num_decode_tokens=inp.num_decode_tokens(), |
| 76 | num_lm_head_tokens=inp.num_lm_head_tokens(), |
| 77 | ) |
| 78 | |
| 79 | input_batch_state = make_input_batch_state( |
| 80 | inp, |
| 81 | tp_rank=tp_rank, |
| 82 | tp_size=tp_size, |
| 83 | num_total_padding=num_total_padding, |
| 84 | num_lm_head_padding=num_lm_head_padding, |
| 85 | ) |
| 86 | |
| 87 | model_runner.plan(input_batch_state, non_blocking=non_blocking) |
| 88 | |
| 89 | move_batch_state( |
| 90 | input_batch_state=input_batch_state, |
| 91 | device=state.device, |
| 92 | non_blocking=non_blocking, |
| 93 | ) |
| 94 | |
| 95 | return Work( |
| 96 | model_input=inp, |
| 97 | input_batch_state=input_batch_state, |
| 98 | batch_indices=batch_indices.to(state.device, non_blocking=non_blocking), |
| 99 | ) |
| 100 | |
| 101 | def run_model(work: Work): |
| 102 | decoding_batch_indices = work.batch_indices[ |
no test coverage detected