@@ -472,24 +472,37 @@ def tracked_metadata(self) -> List[Any]:
472472 return [getattr (sp , field ) for field , _ , _ in self .get_metadata_types ()]
473473
474474 @staticmethod
475- def get_metadata_types () -> List [Tuple [str , torch .dtype , bool ]]:
475+ def get_metadata_types (
476+ sampling_backend : str = 'torch' ,
477+ ) -> List [Tuple [str , torch .dtype , bool ]]:
476478 """Keeps track of all request metadata names, dtypes, and target device.
477479
480+ Args:
481+ sampling_backend: Which sampling backend is in use.
482+ FlashInfer needs sampling parameters directly on GPU.
483+
478484 Returns:
479485 List[Tuple[str, torch.dtype, bool]]: Mapping from metadata name to:
480486 name (str) - The name of the metadata field.
481487 dtype (torch.dtype) - The datatype of the metadata.
482488 on_device (bool) - Whether the metadata lives on GPU (True) or CPU (False).
483489 """
484- return [
485- ("temperature" , torch .float32 , False ), # CPU for torch sampling
486- ("top_k" , torch .int32 , False ), # CPU for torch sampling
487- ("top_p" , torch .float32 , False ), # CPU for torch sampling
490+ types = [
491+ ("temperature" , torch .float32 , False ),
492+ ("top_k" , torch .int32 , False ),
493+ ("top_p" , torch .float32 , False ),
488494 ("termination_id" , torch .int64 , True ),
489- ("return_log_probs" , torch .bool , False ), # CPU for non-selective logprobs
490- ("skip_prompt_log_probs" , torch .bool , False ), # CPU for non-selective logprobs
491- ("top_n_logprobs" , torch .int32 , False ), # CPU for torch sampling
495+ ("return_log_probs" , torch .bool , False ),
496+ ("skip_prompt_log_probs" , torch .bool , False ),
497+ ("top_n_logprobs" , torch .int32 , False ),
492498 ]
499+ if sampling_backend == 'flashinfer' :
500+ gpu_fields = {"temperature" , "top_k" , "top_p" }
501+ types = [
502+ (label , dtype , True if label in gpu_fields else on_gpu )
503+ for label , dtype , on_gpu in types
504+ ]
505+ return types
493506
494507 def add_event (
495508 self , type : DynamicInferenceEventType , payload : Optional [Any ] = None
0 commit comments