Skip to content
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

[HF][fix] Allow kwargs in ModelParser.run() #882

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
import torch
from transformers import pipeline, Pipeline
from aiconfig_extension_hugging_face.local_inference.util import get_hf_model

from aiconfig import ModelParser, InferenceOptions
from aiconfig.callback import CallbackEvent
from aiconfig.default_parsers.parameterized_model_parser import ParameterizedModelParser
from aiconfig.model_parser import InferenceOptions
from aiconfig.schema import Prompt, Output, ExecuteResult, Attachment

if TYPE_CHECKING:
from aiconfig import AIConfigRuntime


class HuggingFaceAutomaticSpeechRecognitionTransformer(ParameterizedModelParser):
class HuggingFaceAutomaticSpeechRecognitionTransformer(ModelParser):
"""
Model Parser for HuggingFace ASR (Automatic Speech Recognition) models.
"""
Expand Down Expand Up @@ -87,7 +85,7 @@ async def deserialize(
await aiconfig.callback_manager.run_callbacks(CallbackEvent("on_deserialize_complete", __name__, {"output": completion_data}))
return completion_data

async def run_inference(self, prompt: Prompt, aiconfig: "AIConfigRuntime", options: InferenceOptions, parameters: Dict[str, Any]) -> List[Output]:
async def run(self, prompt: Prompt, aiconfig: "AIConfigRuntime", options: InferenceOptions, parameters: Dict[str, Any], **kwargs) -> list[Output]:
await aiconfig.callback_manager.run_callbacks(
CallbackEvent(
"on_run_start",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

from aiconfig_extension_hugging_face.local_inference.util import get_hf_model

from aiconfig import ModelParser, InferenceOptions
from aiconfig.callback import CallbackEvent
from aiconfig.default_parsers.parameterized_model_parser import ParameterizedModelParser
from aiconfig.model_parser import InferenceOptions
from aiconfig.schema import (
Attachment,
ExecuteResult,
Expand All @@ -25,7 +24,7 @@
from aiconfig import AIConfigRuntime


class HuggingFaceImage2TextTransformer(ParameterizedModelParser):
class HuggingFaceImage2TextTransformer(ModelParser):
def __init__(self):
"""
Returns:
Expand Down Expand Up @@ -118,7 +117,7 @@ async def deserialize(
await aiconfig.callback_manager.run_callbacks(CallbackEvent("on_deserialize_complete", __name__, {"output": completion_params}))
return completion_params

async def run_inference(self, prompt: Prompt, aiconfig: "AIConfigRuntime", options: InferenceOptions, parameters: Dict[str, Any]) -> List[Output]:
async def run(self, prompt: Prompt, aiconfig: "AIConfigRuntime", options: InferenceOptions, parameters: Dict[str, Any], **kwargs) -> list[Output]:
await aiconfig.callback_manager.run_callbacks(
CallbackEvent(
"on_run_start",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_hf_model(aiconfig: "AIConfigRuntime", prompt: Prompt, model_parser: Para
"""
model_name: str | None = aiconfig.get_model_name(prompt)
model_settings = model_parser.get_model_settings(prompt, aiconfig)
hf_model = model_settings.get("model", None)
hf_model = model_settings.get("model") or None # Replace "" with None value

if hf_model is not None and isinstance(hf_model, str):
# If the model property is set in the model settings, use that.
Expand Down
2 changes: 1 addition & 1 deletion python/src/aiconfig/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ async def run(
options,
params,
callback_manager=self.callback_manager,
**kwargs,
**kwargs, # TODO: We should remove and make argument explicit
)

event = CallbackEvent("on_run_complete", __name__, {"result": response})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def run(
aiconfig: AIConfig,
options: Optional[InferenceOptions] = None,
parameters: Dict = {},
**kwargs,
**kwargs, #TODO: We should remove and make arguments explicit
) -> List[Output]:
# maybe use prompt metadata instead of kwargs?
if kwargs.get("run_with_dependencies", False):
Expand Down
1 change: 1 addition & 0 deletions python/src/aiconfig/model_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ async def run(
aiconfig: AIConfig,
options: Optional["InferenceOptions"] = None,
parameters: Dict = {},
**kwargs, # TODO: Remove this, just a hack for now to ensure that it doesn't break
) -> ExecuteResult:
"""
Execute model inference based on completion data to be constructed in deserialize(), which includes the input prompt and
Expand Down