Skip to content

Commit 2480acc

Browse files
committed
Merge branch 'master' into video-inference
2 parents c397e5d + 7bc9cbb commit 2480acc

20 files changed

+313
-170
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
## [[11.1.4]](https://github.com/Clarifai/clarifai-python/releases/tag/11.1.4) - [PyPI](https://pypi.org/project/clarifai/11.1.4/) - 2025-02-12
2+
3+
### Changed
4+
5+
- Introduce 3 times when you can download checkpoints [(#515)] (https://github.com/Clarifai/clarifai-python/pull/515)
6+
7+
## [[11.1.3]](https://github.com/Clarifai/clarifai-python/releases/tag/11.1.3) - [PyPI](https://pypi.org/project/clarifai/11.1.3/) - 2025-02-11
8+
9+
### Changed
10+
11+
- Fix dependency parsing [(#514)] (https://github.com/Clarifai/clarifai-python/pull/514)
12+
13+
## [[11.1.2]](https://github.com/Clarifai/clarifai-python/releases/tag/11.1.2) - [PyPI](https://pypi.org/project/clarifai/11.1.2/) - 2025-02-10
14+
15+
### Changed
16+
17+
- User new base images and fix clarifai version [(#513)] (https://github.com/Clarifai/clarifai-python/pull/513)
18+
119
## [[11.1.1]](https://github.com/Clarifai/clarifai-python/releases/tag/11.1.1) - [PyPI](https://pypi.org/project/clarifai/11.1.1/) - 2025-02-06
220

321
### Changed

clarifai/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "11.1.1"
1+
__version__ = "11.1.4"

clarifai/cli/model.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,24 @@ def model():
1515
required=True,
1616
help='Path to the model directory.')
1717
@click.option(
18-
'--download_checkpoints',
19-
is_flag=True,
18+
'--stage',
19+
required=False,
20+
type=click.Choice(['runtime', 'build', 'upload'], case_sensitive=True),
21+
default="upload",
22+
show_default=True,
2023
help=
21-
'Flag to download checkpoints before uploading and including them in the tar file that is uploaded. Defaults to False, which will attempt to download them at docker build time.',
24+
'The stage we are calling download checkpoints from. Typically this would "upload" and will download checkpoints if config.yaml checkpoints section has when set to "upload". Other options include "runtime" to be used in load_model or "upload" to be used during model upload. Set this stage to whatever you have in config.yaml to force downloading now.'
2225
)
2326
@click.option(
2427
'--skip_dockerfile',
2528
is_flag=True,
2629
help=
2730
'Flag to skip generating a dockerfile so that you can manually edit an already created dockerfile.',
2831
)
29-
def upload(model_path, download_checkpoints, skip_dockerfile):
32+
def upload(model_path, stage, skip_dockerfile):
3033
"""Upload a model to Clarifai."""
3134
from clarifai.runners.models.model_builder import upload_model
32-
upload_model(model_path, download_checkpoints, skip_dockerfile)
35+
upload_model(model_path, stage, skip_dockerfile)
3336

3437

3538
@model.command()
@@ -44,14 +47,23 @@ def upload(model_path, download_checkpoints, skip_dockerfile):
4447
required=False,
4548
default=None,
4649
help=
47-
'Option path to write the checkpoints to. This will place them in {out_path}/ If not provided it will default to {model_path}/1/checkpoints where the config.yaml is read..'
50+
'Option path to write the checkpoints to. This will place them in {out_path}/1/checkpoints If not provided it will default to {model_path}/1/checkpoints where the config.yaml is read.'
51+
)
52+
@click.option(
53+
'--stage',
54+
required=False,
55+
type=click.Choice(['runtime', 'build', 'upload'], case_sensitive=True),
56+
default="build",
57+
show_default=True,
58+
help=
59+
'The stage we are calling download checkpoints from. Typically this would be in the build stage which is the default. Other options include "runtime" to be used in load_model or "upload" to be used during model upload. Set this stage to whatever you have in config.yaml to force downloading now.'
4860
)
49-
def download_checkpoints(model_path, out_path):
61+
def download_checkpoints(model_path, out_path, stage):
5062
"""Download checkpoints from external source to local model_path"""
5163

5264
from clarifai.runners.models.model_builder import ModelBuilder
5365
builder = ModelBuilder(model_path, download_validation_only=True)
54-
builder.download_checkpoints(out_path)
66+
builder.download_checkpoints(stage=stage, checkpoint_path_override=out_path)
5567

5668

5769
@model.command()
@@ -159,6 +171,18 @@ def run_locally(model_path, port, mode, keep_env, keep_image):
159171
click.echo(f"Failed to starts model server locally: {e}", err=True)
160172

161173

174+
@model.command()
175+
@click.option(
176+
'--model_path',
177+
type=click.Path(exists=True),
178+
required=True,
179+
help='Path to the model directory.')
180+
def local_dev(model_path):
181+
"""Run the model as a local dev runner to help debug your model connected to the API. You must set several envvars such as CLARIFAI_PAT, CLARIFAI_RUNNER_ID, CLARIFAI_NODEPOOL_ID, CLARIFAI_COMPUTE_CLUSTER_ID. """
182+
from clarifai.runners.server import serve
183+
serve(model_path)
184+
185+
162186
@model.command()
163187
@click.option(
164188
'--config',

clarifai/client/model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from clarifai.runners.utils import video_utils
2828
from clarifai.urls.helper import ClarifaiUrlHelper
2929
from clarifai.utils.logging import logger
30-
from clarifai.utils.misc import BackoffIterator
30+
from clarifai.utils.misc import BackoffIterator, status_is_retryable
3131
from clarifai.utils.model_train import (find_and_replace_key, params_parser,
3232
response_to_model_params, response_to_param_info,
3333
response_to_templates)
@@ -439,7 +439,7 @@ def predict(self,
439439
while True:
440440
response = self._grpc_request(self.STUB.PostModelOutputs, request)
441441

442-
if response.status.code == status_code_pb2.MODEL_DEPLOYING and \
442+
if status_is_retryable(response.status.code) and \
443443
time.time() - start_time < 60 * 10: # 10 minutes
444444
self.logger.info(f"{self.id} model is still deploying, please wait...")
445445
time.sleep(next(backoff_iterator))
@@ -722,7 +722,7 @@ def generate(self,
722722
break
723723
stream_response = self._grpc_request(self.STUB.GenerateModelOutputs, request)
724724
for response in stream_response:
725-
if response.status.code == status_code_pb2.MODEL_DEPLOYING and \
725+
if status_is_retryable(response.status.code) and \
726726
time.time() - start_time < 60 * 10:
727727
self.logger.info(f"{self.id} model is still deploying, please wait...")
728728
time.sleep(next(backoff_iterator))
@@ -967,7 +967,7 @@ def stream(self,
967967
break
968968
stream_response = self._grpc_request(self.STUB.StreamModelOutputs, request)
969969
for response in stream_response:
970-
if response.status.code == status_code_pb2.MODEL_DEPLOYING and \
970+
if status_is_retryable(response.status.code) and \
971971
time.time() - start_time < 60 * 10:
972972
self.logger.info(f"{self.id} model is still deploying, please wait...")
973973
time.sleep(next(backoff_iterator))

clarifai/client/workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from clarifai.errors import UserError
1616
from clarifai.urls.helper import ClarifaiUrlHelper
1717
from clarifai.utils.logging import logger
18-
from clarifai.utils.misc import BackoffIterator
18+
from clarifai.utils.misc import BackoffIterator, status_is_retryable
1919
from clarifai.workflows.export import Exporter
2020

2121

@@ -99,7 +99,7 @@ def predict(self, inputs: List[Input], workflow_state_id: str = None):
9999
while True:
100100
response = self._grpc_request(self.STUB.PostWorkflowResults, request)
101101

102-
if response.status.code == status_code_pb2.MODEL_DEPLOYING and \
102+
if status_is_retryable(response.status.code) and \
103103
time.time() - start_time < 60*10: # 10 minutes
104104
self.logger.info(f"{self.id} Workflow is still deploying, please wait...")
105105
time.sleep(next(backoff_iterator))

clarifai/runners/dockerfile_template/Dockerfile.template

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
1-
# syntax=docker/dockerfile:1
2-
#############################
3-
# User specific requirements installed in the pip_packages
4-
#############################
5-
FROM --platform=$TARGETPLATFORM ${BUILDER_IMAGE} as pip_packages
1+
# syntax=docker/dockerfile:1.13-labs
2+
FROM --platform=$TARGETPLATFORM ${FINAL_IMAGE} as final
63

74
COPY --link requirements.txt /home/nonroot/requirements.txt
85

96
# Update clarifai package so we always have latest protocol to the API. Everything should land in /venv
10-
RUN pip install --no-cache-dir -r /home/nonroot/requirements.txt && \
11-
(pip install --upgrade --upgrade-strategy only-if-needed --no-deps --no-cache-dir clarifai clarifai-grpc clarifai-protocol || true)
12-
#############################
13-
14-
#############################
15-
# Downloader dependencies image
16-
#############################
17-
FROM --platform=$TARGETPLATFORM ${DOWNLOADER_IMAGE} as downloader
18-
19-
# make sure we have the latest clarifai package.
20-
RUN (pip install --upgrade --upgrade-strategy only-if-needed --no-cache-dir clarifai clarifai-grpc clarifai-protocol || true)
21-
#####
22-
23-
24-
#############################
25-
# Final runtime image
26-
#############################
27-
FROM --platform=$TARGETPLATFORM ${RUNTIME_IMAGE} as final
7+
RUN ["pip", "install", "--no-cache-dir", "-r", "/home/nonroot/requirements.txt"]
8+
RUN ["pip", "show", "clarifai"]
289

2910
# Set the NUMBA cache dir to /tmp
3011
# Set the TORCHINDUCTOR cache dir to /tmp
@@ -34,28 +15,16 @@ ENV NUMBA_CACHE_DIR=/tmp/numba_cache \
3415
HOME=/tmp \
3516
DEBIAN_FRONTEND=noninteractive
3617

37-
#####
38-
# Copy the python requirements needed to download checkpoints
39-
#####
40-
COPY --link=true --from=downloader /venv /venv
41-
#####
42-
4318
#####
4419
# Copy the files needed to download
4520
#####
4621
# This creates the directory that HF downloader will populate and with nonroot:nonroot permissions up.
4722
COPY --chown=nonroot:nonroot downloader/unused.yaml /home/nonroot/main/1/checkpoints/.cache/unused.yaml
4823

4924
#####
50-
# Download checkpoints
25+
# Download checkpoints if config.yaml has checkpoints.when = "build"
5126
COPY --link=true config.yaml /home/nonroot/main/
52-
RUN ["python", "-m", "clarifai.cli", "model", "download-checkpoints", "--model_path", "/home/nonroot/main", "--out_path", "/home/nonroot/main"]
53-
#####
54-
55-
56-
#####
57-
# Copy the python packages from the previous stage.
58-
COPY --link=true --from=pip_packages /venv /venv
27+
RUN ["python", "-m", "clarifai.cli", "model", "download-checkpoints", "--model_path", "/home/nonroot/main", "--out_path", "/home/nonroot/main/1/checkpoints", "--stage", "build"]
5928
#####
6029

6130
# Copy in the actual files like config.yaml, requirements.txt, and most importantly 1/model.py

0 commit comments

Comments
 (0)