mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-18 00:07:45 +00:00
fix: lint
This commit is contained in:
parent
b0e22eff05
commit
858cf472e2
@ -85,6 +85,7 @@ class ChatGLMAdapater(BaseLLMAdaper):
|
||||
|
||||
class GuanacoAdapter(BaseLLMAdaper):
|
||||
"""TODO Support guanaco"""
|
||||
|
||||
def match(self, model_path: str):
|
||||
return "guanaco" in model_path
|
||||
|
||||
|
@ -6,16 +6,17 @@ import transformers
|
||||
from transformers import GenerationConfig
|
||||
from llm_utils import Iteratorize, Stream
|
||||
|
||||
|
||||
def guanaco_generate_output(model, tokenizer, params, device):
|
||||
"""Fork from fastchat: https://github.com/KohakuBlueleaf/guanaco-lora/blob/main/generate.py"""
|
||||
prompt = params["prompt"]
|
||||
inputs = tokenizer(prompt, return_tensors="pt")
|
||||
input_ids = inputs["input_ids"].to(device)
|
||||
temperature=0.5,
|
||||
top_p=0.95,
|
||||
top_k=45,
|
||||
max_new_tokens=128,
|
||||
stream_output=True
|
||||
temperature = (0.5,)
|
||||
top_p = (0.95,)
|
||||
top_k = (45,)
|
||||
max_new_tokens = (128,)
|
||||
stream_output = True
|
||||
|
||||
generation_config = GenerationConfig(
|
||||
temperature=temperature,
|
||||
@ -37,19 +38,13 @@ def guanaco_generate_output(model, tokenizer, params, device):
|
||||
# from https://github.com/oobabooga/text-generation-webui/blob/ad37f396fc8bcbab90e11ecf17c56c97bfbd4a9c/modules/text_generation.py#L216-L243.
|
||||
|
||||
def generate_with_callback(callback=None, **kwargs):
|
||||
kwargs.setdefault(
|
||||
"stopping_criteria", transformers.StoppingCriteriaList()
|
||||
)
|
||||
kwargs["stopping_criteria"].append(
|
||||
Stream(callback_func=callback)
|
||||
)
|
||||
kwargs.setdefault("stopping_criteria", transformers.StoppingCriteriaList())
|
||||
kwargs["stopping_criteria"].append(Stream(callback_func=callback))
|
||||
with torch.no_grad():
|
||||
model.generate(**kwargs)
|
||||
|
||||
def generate_with_streaming(**kwargs):
|
||||
return Iteratorize(
|
||||
generate_with_callback, kwargs, callback=None
|
||||
)
|
||||
return Iteratorize(generate_with_callback, kwargs, callback=None)
|
||||
|
||||
with generate_with_streaming(**generate_params) as generator:
|
||||
for output in generator:
|
||||
@ -72,7 +67,7 @@ def guanaco_generate_output(model, tokenizer, params, device):
|
||||
)
|
||||
|
||||
s = generation_output.sequences[0]
|
||||
print(f"debug_sequences,{s}",s)
|
||||
print(f"debug_sequences,{s}", s)
|
||||
output = tokenizer.decode(s)
|
||||
print(f"debug_output,{output}",output)
|
||||
print(f"debug_output,{output}", output)
|
||||
yield output.split("### Response:")[-1].strip()
|
@ -53,6 +53,7 @@ def create_chat_completion(
|
||||
response = None
|
||||
# TODO impl this use vicuna server api
|
||||
|
||||
|
||||
class Stream(transformers.StoppingCriteria):
|
||||
def __init__(self, callback_func=None):
|
||||
self.callback_func = callback_func
|
||||
|
@ -85,7 +85,7 @@ class CodeGenChatAdapter(BaseChatAdpter):
|
||||
|
||||
|
||||
class GuanacoChatAdapter(BaseChatAdpter):
|
||||
"""Model chat adapter for Guanaco """
|
||||
"""Model chat adapter for Guanaco"""
|
||||
|
||||
def match(self, model_path: str):
|
||||
return "guanaco" in model_path
|
||||
|
Loading…
Reference in New Issue
Block a user