Skip to content

Commit

Permalink
Merge pull request #51 from BatsResearch/vllm-update
Browse files Browse the repository at this point in the history
Adding Top-k as kwargs for vllm
  • Loading branch information
dotpyu authored Nov 2, 2023
2 parents 561528c + 5f66e18 commit e24adb0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion alfred/fm/vllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, model: str, model_string: str, local_dir: str = None,
super().__init__(model_string)
self.gpu_count = torch.cuda.device_count()
self.model = LLM(local_dir if local_dir is not None else model, tensor_parallel_size=self.gpu_count)

def _generate_batch(
self,
batch_instance: List[str],
Expand All @@ -51,7 +52,8 @@ def _generate_batch(

temperature = kwargs.get("temperature", 0)
max_new_tokens = kwargs.get("max_new_tokens", 16)
top_k = kwargs.get("top_k", -1)

sampling_params = SamplingParams(temperature=temperature, max_tokens=max_new_tokens, top_k=1)
sampling_params = SamplingParams(temperature=temperature, max_tokens=max_new_tokens, top_k=top_k)

return [CompletionResponse(prediction=output.outputs[0].text) for output in self.model.generate(batch_instance, sampling_params)]

0 comments on commit e24adb0

Please sign in to comment.