Skip to content

Conversation

@wemoveon2
Copy link
Contributor

@wemoveon2 wemoveon2 commented Oct 22, 2025

What

  • Currently, the API sends the full model proto as part of each predict request

Why

  • This is unnecessary as we can load the model proto once and reuse it across all requests without depending on the API including it

How

  • Retrieve the model proto once via GetModel and set it in each predict request incase it's needed downstream

Tests

  • Existing tests pass

Notes

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes model runner performance by loading the model proto once at initialization instead of expecting it with every predict request from the API. The model proto is now retrieved via a single GetModel call and reused across all subsequent requests.

Key Changes

  • Added get_model_proto() method to ModelBuilder to fetch model metadata once via GetModel API
  • Updated ModelRunner to accept and store model_proto during initialization
  • Modified predict, generate, and stream methods to inject the cached model_proto into requests

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
clarifai/runners/models/model_builder.py Adds get_model_proto() method to retrieve and return model proto via GetModel API call
clarifai/runners/server.py Passes the retrieved model_proto to ModelRunner during initialization
clarifai/runners/models/model_runner.py Updates constructor to accept model_proto parameter and injects it into all request types (predict, generate, stream)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@wemoveon2 wemoveon2 requested a review from Copilot October 22, 2025 20:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

@wemoveon2 wemoveon2 requested a review from Copilot October 22, 2025 21:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Copy link
Contributor Author

@wemoveon2 wemoveon2 Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue with this is we'll overwrite request type secrets if we don't also add handling for request type secrets to GetModel.

we'll need to ensure that we're populating the value for request type secrets in GetModel endpoint

@wemoveon2 wemoveon2 requested a review from Copilot October 22, 2025 21:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

wemoveon2 and others added 2 commits October 22, 2025 17:15
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@wemoveon2 wemoveon2 requested a review from Copilot October 22, 2025 21:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

@wemoveon2 wemoveon2 requested a review from Copilot October 23, 2025 05:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

wemoveon2 and others added 3 commits October 23, 2025 01:24
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions
Copy link

Code Coverage

Package Line Rate Health
clarifai 45%
clarifai.cli 44%
clarifai.cli.templates 33%
clarifai.client 67%
clarifai.client.auth 67%
clarifai.constants 100%
clarifai.datasets 100%
clarifai.datasets.export 80%
clarifai.datasets.upload 75%
clarifai.datasets.upload.loaders 37%
clarifai.models 100%
clarifai.modules 0%
clarifai.rag 72%
clarifai.runners 52%
clarifai.runners.models 58%
clarifai.runners.pipeline_steps 41%
clarifai.runners.pipelines 70%
clarifai.runners.utils 63%
clarifai.runners.utils.data_types 72%
clarifai.schema 100%
clarifai.urls 60%
clarifai.utils 60%
clarifai.utils.evaluation 67%
clarifai.workflows 95%
Summary 61% (8166 / 13290)

Minimum allowed line rate is 50%

Copy link
Contributor

@luv-bansal luv-bansal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@wemoveon2 wemoveon2 merged commit bf25e09 into master Oct 23, 2025
11 checks passed
@wemoveon2 wemoveon2 deleted the 5341 branch October 23, 2025 15:42
srikanthbachala20 pushed a commit that referenced this pull request Oct 24, 2025
…request (#822)

* load model proto from GetModel request and set it for every predict request

* Update clarifai/runners/models/model_runner.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Revert "Update clarifai/runners/models/model_runner.py"

This reverts commit f603dff.

* fix suggestion

* only set if none

* suggestion

* Update clarifai/runners/models/model_runner.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix condition

* fix tests

* Update clarifai/runners/models/model_runner.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update clarifai/runners/models/model_builder.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix test

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

def start_servicer(self, port, pool_size, max_queue_size, max_msg_length, enable_tls):
# initialize the servicer with the runner so that it gets the predict(), generate(), stream() classes.
self._servicer = ModelServicer(self._current_model)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this path missing the model proto since it's only added to the ModelRunner. How come we wouldn't GetModel in the self._current_model so it's proto and model class are always together regardless of how they are served. @luv-bansal @wemoveon2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants