-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support custom specified models for HF model parsers #863
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
TextIteratorStreamer, | ||
) | ||
|
||
from aiconfig_extension_hugging_face.local_inference.util import get_hf_model | ||
|
||
from aiconfig.default_parsers.parameterized_model_parser import ParameterizedModelParser | ||
from aiconfig.model_parser import InferenceOptions | ||
from aiconfig.schema import ( | ||
|
@@ -242,16 +244,15 @@ async def run_inference(self, prompt: Prompt, aiconfig: "AIConfigRuntime", optio | |
completion_data = await self.deserialize(prompt, aiconfig, options, parameters) | ||
inputs = completion_data.pop("prompt", None) | ||
|
||
model_name: str = aiconfig.get_model_name(prompt) | ||
if isinstance(model_name, str) and model_name not in self.summarizers: | ||
self.summarizers[model_name] = pipeline("summarization", model=model_name) | ||
summarizer = self.summarizers[model_name] | ||
model_name = get_hf_model(aiconfig, prompt, self) | ||
key = model_name if model_name is not None else "__default__" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
if key not in self.summarizers: | ||
self.summarizers[key] = pipeline("summarization", model=model_name) | ||
summarizer = self.summarizers[key] | ||
|
||
# if stream enabled in runtime options and config, then stream. Otherwise don't stream. | ||
streamer = None | ||
should_stream = (options.stream if options else False) and ( | ||
not "stream" in completion_data or completion_data.get("stream") != False | ||
) | ||
should_stream = (options.stream if options else False) and (not "stream" in completion_data or completion_data.get("stream") != False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not for this diff but this stream logic should be cleaned up There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have an bootcamp issue to track this in #861 |
||
if should_stream: | ||
tokenizer: AutoTokenizer = AutoTokenizer.from_pretrained(model_name) | ||
streamer = TextIteratorStreamer(tokenizer) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: double underscores are usually associated with dunder methods or special built-in values in Python. Would prefer a different value here To avoid any confusion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can make a little enum class or something, like
Then check for that value wherever needed and supply the real default value in a specific use case