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

Python: Fix Onnx Connector Memory Problem with Onnx #9716

Merged
merged 6 commits into from
Nov 29, 2024
Merged
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 @@ -53,31 +53,25 @@ def __init__(self, ai_model_path: str, **kwargs) -> None:
**kwargs,
)

def _prepare_input_params(
self, prompt: str, settings: OnnxGenAIPromptExecutionSettings, image: ImageContent | None = None
) -> Any:
params = OnnxRuntimeGenAi.GeneratorParams(self.model)
params.set_search_options(**settings.prepare_settings_dict())
if not self.enable_multi_modality:
input_tokens = self.tokenizer.encode(prompt)
params.input_ids = input_tokens
else:
if image is not None:
# With the use of Pybind there is currently no way to load images from bytes
# We can only open images from a file path currently
image = OnnxRuntimeGenAi.Images.open(str(image.uri))
input_tokens = self.tokenizer(prompt, images=image)
params.set_inputs(input_tokens)
return params

async def _generate_next_token_async(
self,
prompt: str,
settings: OnnxGenAIPromptExecutionSettings,
image: ImageContent | None = None,
) -> AsyncGenerator[list[str], Any]:
try:
params = self._prepare_input_params(prompt, settings, image)
params = OnnxRuntimeGenAi.GeneratorParams(self.model)
params.set_search_options(**settings.prepare_settings_dict())
if not self.enable_multi_modality:
input_tokens = self.tokenizer.encode(prompt)
params.input_ids = input_tokens
else:
if image is not None:
# With the use of Pybind there is currently no way to load images from bytes
# We can only open images from a file path currently
image = OnnxRuntimeGenAi.Images.open(str(image.uri))
input_tokens = self.tokenizer(prompt, images=image)
params.set_inputs(input_tokens)
generator = OnnxRuntimeGenAi.Generator(self.model, params)

while not generator.is_done():
Expand Down
Loading