Skip to content

[PR-674] fix legacy proto support #636

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

luv-bansal
Copy link
Contributor

@luv-bansal luv-bansal commented Jun 18, 2025

Pull Request Overview

This PR enhances support for legacy proto-style model methods by introducing detection and special handling, along with adding tests and required configuration changes.

  • Add is_proto_style_method and integrate proto-method handling in ModelClass
  • Rename _get_method_info_get_method_infos across code, tests, and builder scripts
  • Introduce new runner integration tests and a dummy proto-based runner model

Comment on lines 399 to 403
for name in ['predict']: # , 'generate', 'stream'):
if hasattr(cls, name):
method = getattr(cls, name)
if name not in methods: # not already put in registry
methods[name] = _MethodInfo(method, proto_method=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this only checks for a class attribute — not necessarily a method. And if it is a method, it ensures it's not decorated with @ModelClass.method and is named predict. I don't think it ensures a method is in old proto-style method that returns a proto.

Comment on lines 399 to 403
for name in ['predict']: # , 'generate', 'stream'):
if hasattr(cls, name):
method = getattr(cls, name)
if name not in methods: # not already put in registry
methods[name] = _MethodInfo(method, proto_method=True)
Copy link
Contributor Author

@luv-bansal luv-bansal Jun 20, 2025

Choose a reason for hiding this comment

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

@zeiler I think this only checks for a class attribute — not necessarily a method. And if it is a method, it ensures it's not decorated with @ModelClass.method and is named predict. I don't think it ensures a method is in old proto-style method that returns a proto.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in my follow-up commit

@luv-bansal luv-bansal requested review from zeiler and Copilot June 20, 2025 08:42
Copilot

This comment was marked as outdated.

@luv-bansal luv-bansal requested a review from Copilot June 20, 2025 08:46
Copy link
Contributor

@Copilot 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 enhances support for legacy proto-style model methods by introducing detection and special handling, renaming the method-info API, and updating tests and utilities accordingly.

  • Add is_proto_style_method and integrate proto-method handling in ModelClass
  • Rename _get_method_info_get_method_infos across code, tests, and builder scripts
  • Introduce new runner integration tests and a dummy proto-based runner model

Reviewed Changes

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

Show a summary per file
File Description
tests/runners/test_runners_proto.py New end-to-end tests for the proto runner server
tests/runners/test_model_signatures.py Updated signature tests to use _get_method_infos()
tests/runners/dummy_runner_proto_model/requirements.txt Added dependencies for dummy runner model
tests/runners/dummy_runner_proto_model/config.yaml Configuration for dummy runner proto model
tests/runners/dummy_runner_proto_model/1/model.py Dummy runner implementation handling text and image inputs
setup.py Exclude ruff from install_requires
clarifai/runners/utils/model_utils.py Added is_proto_style_method helper
clarifai/runners/utils/code_script.py Guard against None method signatures in script gen
clarifai/runners/models/model_class.py Rename API, register proto-style methods, use logger
clarifai/runners/models/model_builder.py Updated builder to call _get_method_infos()
Comments suppressed due to low confidence (1)

clarifai/runners/utils/model_utils.py:140

  • There are no unit tests covering the new is_proto_style_method function. Adding tests for its various signature patterns would help prevent regressions.
def is_proto_style_method(method):

if not proto_method:
self.signature = build_function_signature(method)
else:
self.signature = None
self.python_param_types = {
Copy link
Preview

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

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

The python_param_types dict currently includes all parameters (including self) and unannotated ones. You should filter out 'self' and only include parameters with explicit annotations, as in the previous implementation (if p.annotation != inspect.Parameter.empty and then pop('self', None)).

Copilot uses AI. Check for mistakes.

Copy link

Code Coverage

Package Line Rate Health
clarifai 43%
clarifai.cli 40%
clarifai.client 68%
clarifai.client.auth 66%
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 12%
clarifai.runners.models 58%
clarifai.runners.pipeline_steps 0%
clarifai.runners.utils 59%
clarifai.runners.utils.data_types 72%
clarifai.schema 100%
clarifai.urls 58%
clarifai.utils 73%
clarifai.utils.evaluation 67%
clarifai.workflows 95%
Summary 61% (6595 / 10729)

Minimum allowed line rate is 50%

@luv-bansal luv-bansal changed the title fix legacy proto support [PR-674] fix legacy proto support Jun 20, 2025
return any(method_signature.name == name for method_signature in method_signatures)
return any(
method_signature.name == name for method_signature in method_signatures if method_signature
)


def generate_client_script(
Copy link
Member

Choose a reason for hiding this comment

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

i never implemented what the API call is in the code snippet, that would be the only thing missing showing how to use the client properly to call this proto method. Most of the SDK functions like model.predict() I believe are still in this format so should work?

# if not hasattr(method, _METHOD_INFO_ATTR): # not already put in registry
# methods[name] = _MethodInfo(method)
# older models never had generate or stream so don't bother with them.
for name in ['predict']: # , 'generate', 'stream'):
Copy link
Member

Choose a reason for hiding this comment

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

wonder if we should use the word "PostModelOutputs" to match the grpc call with the method name? Then it would be something very unlikely for a user to use as a function name when implementing their own model while being more clear for us that this is the proto handler? If we change it there is another hard coded "predict" above in this code that matches this method name.

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.

2 participants