-
Notifications
You must be signed in to change notification settings - Fork 579
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
fix partial wrappers and deferred annotations #1895
Open
technillogue
wants to merge
4
commits into
main
Choose a base branch
from
syl/fix-deferred-annotations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
09d81a3
Revert "Revert "Handle predictors with deferred annotations (#1772)" …
technillogue 1d8dea9
add test for partial
technillogue 7720523
fix defered annotations
technillogue 7789385
tweaks to separate -> None from -> Signature.empty
technillogue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test-integration/test_integration/fixtures/future-annotations-project/predict.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from __future__ import annotations | ||
|
||
from cog import BasePredictor, Input | ||
|
||
|
||
class Predictor(BasePredictor): | ||
def predict(self, input: str = Input(description="Who to greet")) -> str: | ||
return "hello " + input |
4 changes: 4 additions & 0 deletions
4
test-integration/test_integration/fixtures/partial-predict-project/cog.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build: | ||
python_version: "3.8" | ||
predict: "predict.py:Predictor" | ||
train: "predict.py:train" |
39 changes: 39 additions & 0 deletions
39
test-integration/test_integration/fixtures/partial-predict-project/predict.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import functools | ||
import inspect | ||
from typing import Any, Callable | ||
|
||
from cog import BasePredictor, Input | ||
|
||
|
||
class Predictor(BasePredictor): | ||
def general( | ||
self, prompt: str = Input(description="hi"), system_prompt: str = None | ||
) -> int: | ||
return 1 | ||
|
||
def _remove(f: Callable, defaults: "dict[str, Any]") -> Callable: | ||
# pylint: disable=no-self-argument | ||
def wrapper(self, *args, **kwargs): | ||
kwargs.update(defaults) | ||
return f(self, *args, **kwargs) | ||
|
||
# Update wrapper attributes for documentation, etc. | ||
functools.update_wrapper(wrapper, f) | ||
|
||
# for the purposes of inspect.signature as used by predictor.get_input_type, | ||
# remove the argument (system_prompt) | ||
sig = inspect.signature(f) | ||
params = [p for name, p in sig.parameters.items() if name not in defaults] | ||
wrapper.__signature__ = sig.replace(parameters=params) | ||
|
||
# Return partialmethod, wrapper behaves correctly when part of a class | ||
return functools.partialmethod(wrapper) | ||
|
||
predict = _remove(general, {"system_prompt": ""}) | ||
|
||
|
||
def _train(prompt: str = Input(description="hi"), system_prompt: str = None) -> int: | ||
return 1 | ||
|
||
|
||
train = functools.partial(_train, system_prompt="") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this need to be an integration test? Could it be a worker test instead?
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.
I was just following #1772, should test_predict_works_with_deferred_annotations be moved as well?
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.
Ah, right. I'd be tempted to move both of those into
test_worker
if it's possible to reproduce the original failure there. It's not really clear to me what the original failure was, though, so it's possible that doesn't work.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.
https://replicatehq.slack.com/archives/C05600FDYTE/p1723843667345019
and
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.
I think it needs to at least be a predictor test because I don't think worker calls get_input_type, though a schema test would work too