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

allow setup(self, weights: str) #1559

Merged
merged 2 commits into from
Mar 14, 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
11 changes: 7 additions & 4 deletions python/cog/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@


class BasePredictor(ABC):
def setup(self, weights: Optional[Union[CogFile, CogPath]] = None) -> None:
def setup(self, weights: Optional[Union[CogFile, CogPath, str]] = None) -> None:
"""
An optional method to prepare the model so multiple predictions run efficiently.
"""
Expand All @@ -70,7 +70,7 @@ def run_setup(predictor: BasePredictor) -> None:
predictor.setup()
return

weights: Union[io.IOBase, Path, None]
weights: Union[io.IOBase, Path, str, None]

weights_url = os.environ.get("COG_WEIGHTS")
weights_path = "weights"
Expand All @@ -85,9 +85,12 @@ def run_setup(predictor: BasePredictor) -> None:
elif weights_type == CogPath:
# TODO: So this can be a url. evil!
weights = cast(CogPath, CogPath.validate(weights_url))
# allow people to download weights themselves
elif weights_type == str:
weights = weights_url
else:
raise ValueError(
f"Predictor.setup() has an argument 'weights' of type {weights_type}, but only File and Path are supported"
f"Predictor.setup() has an argument 'weights' of type {weights_type}, but only File, Path and str are supported"
)
elif os.path.exists(weights_path):
if weights_type == CogFile:
Expand All @@ -96,7 +99,7 @@ def run_setup(predictor: BasePredictor) -> None:
weights = CogPath(weights_path)
else:
raise ValueError(
f"Predictor.setup() has an argument 'weights' of type {weights_type}, but only File and Path are supported"
f"Predictor.setup() has an argument 'weights' of type {weights_type}, but only File, Path and str are supported"
)
else:
weights = None
Expand Down