Add profiling capabilities for processor components in streaming model. Introduce _patch_component_call to time component invocations and enhance _install_profiling_hooks with new processor stages. Refactor tensor conversion and device transfer functions for improved clarity and performance. Update profiling summary to include new stages and advice for optimization.

This commit is contained in:
Xin Wang
2026-08-18 11:20:55 +08:00
parent 43f47e8f3a
commit 609b2781d4
2 changed files with 119 additions and 5 deletions

View File

@@ -565,12 +565,31 @@ def _prepare_conversation(
):
processor_inputs["images"] = images
batch = processor(**processor_inputs)
batch = batch.convert_to_tensors("pt")
batch = _processor_batch_convert_to_tensors(batch)
# BatchFeature.to(dtype) changes floating tensors only; IDs stay integral.
batch = batch.to(model.device).to(model.dtype)
batch = _processor_batch_to_device(batch, model.device)
batch = _processor_batch_to_dtype(batch, model.dtype)
return dict(batch)
def _processor_batch_convert_to_tensors(batch: Any) -> Any:
"""Materialize the processor's NumPy/list outputs as PyTorch tensors."""
return batch.convert_to_tensors("pt")
def _processor_batch_to_device(batch: Any, device: torch.device) -> Any:
"""Move one processor batch to the model device."""
return batch.to(device)
def _processor_batch_to_dtype(batch: Any, dtype: torch.dtype) -> Any:
"""Cast only floating processor tensors to the model dtype."""
return batch.to(dtype)
def _readout_query_ids(
processor: Qwen2_5OmniProcessor,
device: torch.device,