-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from BatsResearch/integrate-vllm
Integrate vLLM
- Loading branch information
Showing
45 changed files
with
116 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import logging | ||
from typing import List, Any | ||
|
||
from alfred.fm.model import LocalAccessFoundationModel | ||
from .response import CompletionResponse | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
import torch | ||
try: | ||
from vllm import LLM, SamplingParams | ||
except ImportError: | ||
raise ImportError("Please install VLLM with `pip install vllm`") | ||
|
||
|
||
|
||
class vLLMModel(LocalAccessFoundationModel): | ||
""" | ||
vLLMModel wraps a vLLM model. vLLM is a fast and easy-to-use library for LLM inference. | ||
source: https://github.com/vllm-project/vllm | ||
""" | ||
|
||
def __init__(self, model: str, model_string: str, local_dir: str = None, | ||
**kwargs: Any): | ||
""" | ||
Initialize a VLLM with MultiGPU. | ||
:param model: (optional) The path to the model. | ||
:type model: str | ||
""" | ||
self.model_string = model | ||
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], | ||
**kwargs: Any, | ||
) -> List[CompletionResponse]: | ||
""" | ||
Generate completions for a batch of queries. | ||
:param batch_instance: A list of queries. | ||
:type batch_instance: List[str] | ||
:param kwargs: Additional keyword arguments. | ||
:return: A list of `CompletionResponse` objects with the same prediction content as the input. | ||
:rtype: List[CompletionResponse] | ||
""" | ||
|
||
temperature = kwargs.get("temperature", 0) | ||
max_new_tokens = kwargs.get("max_new_tokens", 16) | ||
|
||
sampling_params = SamplingParams(temperature=temperature, max_tokens=max_new_tokens, top_k=1) | ||
|
||
return [CompletionResponse(prediction=output.outputs[0].text) for output in self.model.generate(batch_instance, sampling_params)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -372,6 +372,4 @@ Type: *str* | |
```python | ||
def to_metadata_string(**kwargs: Any) -> str: | ||
... | ||
``` | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,4 @@ Stop the tunnel | |
```python | ||
def stop(self): | ||
... | ||
``` | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -614,6 +614,4 @@ returns the version of the dataset | |
```python | ||
def version(self) -> str: | ||
... | ||
``` | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,4 @@ returns the version of the dataset | |
@property | ||
def version(self) -> str: | ||
... | ||
``` | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,4 @@ returns the string representation of the dataset | |
```python | ||
def __repr__(self): | ||
... | ||
``` | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,4 @@ Launch an interactive chat session with the Anthropic API. | |
```python | ||
def chat(self, **kwargs: Any): | ||
... | ||
``` | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,4 @@ Launch an interactive chat session with the OpenAI API. | |
```python | ||
def chat(self, **kwargs: Any): | ||
... | ||
``` | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,4 @@ returns the raw prompt content | |
@property | ||
def prompt(self): | ||
... | ||
``` | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,4 @@ Type: *str* | |
```python | ||
def serialize(self) -> str: | ||
... | ||
``` | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,6 +195,4 @@ returns the raw prompt content | |
@property | ||
def prompt(self): | ||
... | ||
``` | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.