clarifai 11.1.3__py3-none-any.whl → 11.1.4rc2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. clarifai/__init__.py +1 -1
  2. clarifai/__pycache__/__init__.cpython-310.pyc +0 -0
  3. clarifai/__pycache__/errors.cpython-310.pyc +0 -0
  4. clarifai/__pycache__/versions.cpython-310.pyc +0 -0
  5. clarifai/cli/__main__.py~ +4 -0
  6. clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  7. clarifai/cli/__pycache__/__main__.cpython-310.pyc +0 -0
  8. clarifai/cli/__pycache__/base.cpython-310.pyc +0 -0
  9. clarifai/cli/__pycache__/compute_cluster.cpython-310.pyc +0 -0
  10. clarifai/cli/__pycache__/deployment.cpython-310.pyc +0 -0
  11. clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
  12. clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
  13. clarifai/cli/model.py +18 -5
  14. clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
  15. clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
  16. clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
  17. clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
  18. clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
  19. clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
  20. clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
  21. clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
  22. clarifai/client/__pycache__/runner.cpython-310.pyc +0 -0
  23. clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
  24. clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
  25. clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
  26. clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
  27. clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
  28. clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
  29. clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
  30. clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
  31. clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
  32. clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
  33. clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
  34. clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
  35. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
  36. clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
  37. clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
  38. clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
  39. clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
  40. clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
  41. clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
  42. clarifai/models/__pycache__/__init__.cpython-310.pyc +0 -0
  43. clarifai/models/model_serving/__pycache__/__init__.cpython-310.pyc +0 -0
  44. clarifai/models/model_serving/__pycache__/constants.cpython-310.pyc +0 -0
  45. clarifai/models/model_serving/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  46. clarifai/models/model_serving/cli/__pycache__/_utils.cpython-310.pyc +0 -0
  47. clarifai/models/model_serving/cli/__pycache__/base.cpython-310.pyc +0 -0
  48. clarifai/models/model_serving/cli/__pycache__/build.cpython-310.pyc +0 -0
  49. clarifai/models/model_serving/cli/__pycache__/create.cpython-310.pyc +0 -0
  50. clarifai/models/model_serving/model_config/__pycache__/__init__.cpython-310.pyc +0 -0
  51. clarifai/models/model_serving/model_config/__pycache__/base.cpython-310.pyc +0 -0
  52. clarifai/models/model_serving/model_config/__pycache__/config.cpython-310.pyc +0 -0
  53. clarifai/models/model_serving/model_config/__pycache__/inference_parameter.cpython-310.pyc +0 -0
  54. clarifai/models/model_serving/model_config/__pycache__/output.cpython-310.pyc +0 -0
  55. clarifai/models/model_serving/model_config/triton/__pycache__/__init__.cpython-310.pyc +0 -0
  56. clarifai/models/model_serving/model_config/triton/__pycache__/serializer.cpython-310.pyc +0 -0
  57. clarifai/models/model_serving/model_config/triton/__pycache__/triton_config.cpython-310.pyc +0 -0
  58. clarifai/models/model_serving/model_config/triton/__pycache__/wrappers.cpython-310.pyc +0 -0
  59. clarifai/models/model_serving/repo_build/__pycache__/__init__.cpython-310.pyc +0 -0
  60. clarifai/models/model_serving/repo_build/__pycache__/build.cpython-310.pyc +0 -0
  61. clarifai/models/model_serving/repo_build/static_files/__pycache__/base_test.cpython-310-pytest-7.2.0.pyc +0 -0
  62. clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
  63. clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
  64. clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
  65. clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
  66. clarifai/runners/__pycache__/server.cpython-310.pyc +0 -0
  67. clarifai/runners/dockerfile_template/Dockerfile.debug +11 -0
  68. clarifai/runners/dockerfile_template/Dockerfile.debug~ +9 -0
  69. clarifai/runners/dockerfile_template/Dockerfile.template +2 -2
  70. clarifai/runners/models/__pycache__/__init__.cpython-310.pyc +0 -0
  71. clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
  72. clarifai/runners/models/__pycache__/model_builder.cpython-310.pyc +0 -0
  73. clarifai/runners/models/__pycache__/model_class.cpython-310.pyc +0 -0
  74. clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc +0 -0
  75. clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc +0 -0
  76. clarifai/runners/models/__pycache__/model_servicer.cpython-310.pyc +0 -0
  77. clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
  78. clarifai/runners/models/model_builder.py +69 -31
  79. clarifai/runners/models/model_run_locally.py +2 -1
  80. clarifai/runners/models/model_upload.py +607 -0
  81. clarifai/runners/utils/#const.py# +30 -0
  82. clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  83. clarifai/runners/utils/__pycache__/const.cpython-310.pyc +0 -0
  84. clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc +0 -0
  85. clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
  86. clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
  87. clarifai/runners/utils/__pycache__/logging.cpython-310.pyc +0 -0
  88. clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc +0 -0
  89. clarifai/runners/utils/const.py +6 -0
  90. clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
  91. clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
  92. clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  93. clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
  94. clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
  95. clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
  96. clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
  97. clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
  98. clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
  99. clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
  100. {clarifai-11.1.3.dist-info → clarifai-11.1.4rc2.dist-info}/METADATA +15 -26
  101. clarifai-11.1.4rc2.dist-info/RECORD +194 -0
  102. {clarifai-11.1.3.dist-info → clarifai-11.1.4rc2.dist-info}/WHEEL +1 -1
  103. clarifai-11.1.3.dist-info/RECORD +0 -101
  104. {clarifai-11.1.3.dist-info → clarifai-11.1.4rc2.dist-info}/LICENSE +0 -0
  105. {clarifai-11.1.3.dist-info → clarifai-11.1.4rc2.dist-info}/entry_points.txt +0 -0
  106. {clarifai-11.1.3.dist-info → clarifai-11.1.4rc2.dist-info}/top_level.txt +0 -0
clarifai/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "11.1.3"
1
+ __version__ = "11.1.4rc2"
@@ -0,0 +1,4 @@
1
+ from my_cli_tool.cli import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
clarifai/cli/model.py CHANGED
@@ -18,7 +18,7 @@ def model():
18
18
  '--download_checkpoints',
19
19
  is_flag=True,
20
20
  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.',
21
+ 'Flag to download checkpoints before uploading and including them in the tar file that is uploaded. Defaults to False, which will use the "when" field in config.yaml checkpoints section which can be "upload", "build", or "runtime".',
22
22
  )
23
23
  @click.option(
24
24
  '--skip_dockerfile',
@@ -29,7 +29,11 @@ def model():
29
29
  def upload(model_path, download_checkpoints, skip_dockerfile):
30
30
  """Upload a model to Clarifai."""
31
31
  from clarifai.runners.models.model_builder import upload_model
32
- upload_model(model_path, download_checkpoints, skip_dockerfile)
32
+ if download_checkpoints:
33
+ stage = "any" # ignore config.yaml and force download now.
34
+ else:
35
+ stage = "upload"
36
+ upload_model(model_path, stage, skip_dockerfile)
33
37
 
34
38
 
35
39
  @model.command()
@@ -44,14 +48,23 @@ def upload(model_path, download_checkpoints, skip_dockerfile):
44
48
  required=False,
45
49
  default=None,
46
50
  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..'
51
+ '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.'
52
+ )
53
+ @click.option(
54
+ '--stage',
55
+ type=str,
56
+ required=False,
57
+ default="build",
58
+ show_default=True,
59
+ help=
60
+ '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, "upload" to be used during model upload or "any" which will force download now regardless of config.yaml'
48
61
  )
49
- def download_checkpoints(model_path, out_path):
62
+ def download_checkpoints(model_path, out_path, stage):
50
63
  """Download checkpoints from external source to local model_path"""
51
64
 
52
65
  from clarifai.runners.models.model_builder import ModelBuilder
53
66
  builder = ModelBuilder(model_path, download_validation_only=True)
54
- builder.download_checkpoints(out_path)
67
+ builder.download_checkpoints(stage=stage, checkpoint_path_override=out_path)
55
68
 
56
69
 
57
70
  @model.command()
@@ -0,0 +1,11 @@
1
+ FROM --platform=$TARGETPLATFORM public.ecr.aws/docker/library/python:3.12-slim-bookworm as pybase
2
+
3
+ #############################
4
+ # Final runtime image
5
+ #############################
6
+ FROM --platform=$TARGETPLATFORM ${RUNTIME_IMAGE} as final
7
+
8
+ COPY --from=pybase --link=true /usr/bin/ls /usr/bin/cat /usr/bin/which /usr/bin/bash /usr/bin/sort /usr/bin/du /usr/bin/
9
+ COPY --from=pybase --link=true /bin/rbash /bin/sh /bin/rm /bin/
10
+ COPY --from=pybase --link=true /lib/*-linux-gnu/libselinux.so.1 /lib/*-linux-gnu/libpcre2-8.so.0 /lib/x86_64-linux-gnu/
11
+ COPY --from=pybase --link=true /lib/*-linux-gnu/libselinux.so.1 /lib/*-linux-gnu/libpcre2-8.so.0 /lib/aarch64-linux-gnu/
@@ -0,0 +1,9 @@
1
+ FROM --platform=$TARGETPLATFORM public.ecr.aws/docker/library/python:3.12-slim-bookworm as pybase
2
+
3
+ #############################
4
+ # Final runtime image
5
+ #############################
6
+ FROM --platform=$TARGETPLATFORM ${RUNTIME_IMAGE} as final
7
+
8
+ COPY --from=pybase --link=true /usr/bin/ls /usr/bin/cat /usr/bin/which /usr/bin/bash /usr/bin/sort /usr/bin/du /usr/bin/
9
+ COPY --from=pybase --link=true /bin/rbash /bin/sh /bin/rm /bin/
@@ -47,9 +47,9 @@ COPY --link=true --from=downloader /venv /venv
47
47
  COPY --chown=nonroot:nonroot downloader/unused.yaml /home/nonroot/main/1/checkpoints/.cache/unused.yaml
48
48
 
49
49
  #####
50
- # Download checkpoints
50
+ # Download checkpoints if config.yaml has checkpoints.when = "build"
51
51
  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"]
52
+ RUN ["python", "-m", "clarifai.cli", "model", "download-checkpoints", "--model_path", "/home/nonroot/main", "--out_path", "/home/nonroot/main/1/checkpoints", "--stage", "build"]
53
53
  #####
54
54
 
55
55
 
@@ -16,9 +16,10 @@ from rich.markup import escape
16
16
 
17
17
  from clarifai.client import BaseClient
18
18
  from clarifai.runners.models.model_class import ModelClass
19
- from clarifai.runners.utils.const import (AVAILABLE_PYTHON_IMAGES, AVAILABLE_TORCH_IMAGES,
20
- CONCEPTS_REQUIRED_MODEL_TYPE, DEFAULT_PYTHON_VERSION,
21
- PYTHON_BASE_IMAGE, TORCH_BASE_IMAGE)
19
+ from clarifai.runners.utils.const import (
20
+ AVAILABLE_PYTHON_IMAGES, AVAILABLE_TORCH_IMAGES, CONCEPTS_REQUIRED_MODEL_TYPE,
21
+ DEFAULT_DOWNLOAD_CHECKPOINT_WHEN, DEFAULT_PYTHON_VERSION, DEFAULT_RUNTIME_DOWNLOAD_PATH,
22
+ PYTHON_BASE_IMAGE, TORCH_BASE_IMAGE)
22
23
  from clarifai.runners.utils.loader import HuggingFaceLoader
23
24
  from clarifai.urls.helper import ClarifaiUrlHelper
24
25
  from clarifai.utils.logging import logger
@@ -145,11 +146,25 @@ class ModelBuilder:
145
146
  :return: repo_id location of checkpoint.
146
147
  :return: hf_token token to access checkpoint.
147
148
  """
149
+ if "checkpoints" not in self.config:
150
+ return None, None, None, DEFAULT_DOWNLOAD_CHECKPOINT_WHEN
148
151
  assert "type" in self.config.get("checkpoints"), "No loader type specified in the config file"
149
152
  loader_type = self.config.get("checkpoints").get("type")
150
153
  if not loader_type:
151
154
  logger.info("No loader type specified in the config file for checkpoints")
152
155
  return None, None, None
156
+ checkpoints = self.config.get("checkpoints")
157
+ if 'when' not in checkpoints:
158
+ logger.warn(
159
+ f"No 'when' specified in the config file for checkpoints, defaulting to download at {DEFAULT_DOWNLOAD_CHECKPOINT_WHEN}"
160
+ )
161
+ when = checkpoints.get("when", DEFAULT_DOWNLOAD_CHECKPOINT_WHEN)
162
+ # In the config.yaml we don't allow "any", that's only used in download_checkpoints to force download.
163
+ assert when in [
164
+ "upload",
165
+ "build",
166
+ "runtime",
167
+ ], "Invalid value for when in the checkpoint loader when, needs to be one of ['upload', 'build', 'runtime']"
153
168
  assert loader_type == "huggingface", "Only huggingface loader supported for now"
154
169
  if loader_type == "huggingface":
155
170
  assert "repo_id" in self.config.get("checkpoints"), "No repo_id specified in the config file"
@@ -157,7 +172,7 @@ class ModelBuilder:
157
172
 
158
173
  # get from config.yaml otherwise fall back to HF_TOKEN env var.
159
174
  hf_token = self.config.get("checkpoints").get("hf_token", os.environ.get("HF_TOKEN", None))
160
- return loader_type, repo_id, hf_token
175
+ return loader_type, repo_id, hf_token, when
161
176
 
162
177
  def _check_app_exists(self):
163
178
  resp = self.client.STUB.GetApp(service_pb2.GetAppRequest(user_app_id=self.client.user_app_id))
@@ -202,7 +217,7 @@ class ModelBuilder:
202
217
  assert model_type_id in CONCEPTS_REQUIRED_MODEL_TYPE, f"Model type {model_type_id} not supported for concepts"
203
218
 
204
219
  if self.config.get("checkpoints"):
205
- loader_type, _, hf_token = self._validate_config_checkpoints()
220
+ loader_type, _, hf_token, _ = self._validate_config_checkpoints()
206
221
 
207
222
  if loader_type == "huggingface" and hf_token:
208
223
  is_valid_token = HuggingFaceLoader.validate_hftoken(hf_token)
@@ -434,25 +449,43 @@ class ModelBuilder:
434
449
  def tar_file(self):
435
450
  return f"{self.folder}.tar.gz"
436
451
 
437
- def download_checkpoints(self, checkpoint_path_override: str = None):
452
+ def default_runtime_checkpoint_path(self):
453
+ return DEFAULT_RUNTIME_DOWNLOAD_PATH
454
+
455
+ def download_checkpoints(self, stage: str, checkpoint_path_override: str = None):
438
456
  """
439
457
  Downloads the checkpoints specified in the config file.
440
458
 
441
- :param checkpoint_path_override: The path to download the checkpoints to. If not provided, the
442
- default path is used based on the folder ModelUploader was initialized with. The
443
- checkpoint_suffix will be appended to the path.
459
+ :param stage: The stage of the build process. This is used to determine when to download the
460
+ checkpoints. The stage can be one of ['build', 'upload', 'runtime', 'any']. If "any" it will always try to download
461
+ regardless of what is specified in config.yaml. Otherwise it must match what is in config.yaml
462
+ :param checkpoint_path_override: The path to download the checkpoints to (with 1/checkpoints added as suffix). If not provided, the
463
+ default path is used based on the folder ModelUploader was initialized with. The checkpoint_suffix will be appended to the path.
464
+ If stage is 'runtime' and checkpoint_path_override is None, the default runtime path will be used.
465
+
466
+ :return: The path to the downloaded checkpoints. Even if it doesn't download anything, it will return the default path.
444
467
  """
468
+ path = self.checkpoint_path # default checkpoint path.
445
469
  if not self.config.get("checkpoints"):
446
470
  logger.info("No checkpoints specified in the config file")
447
- return True
471
+ return path
448
472
 
449
- loader_type, repo_id, hf_token = self._validate_config_checkpoints()
473
+ loader_type, repo_id, hf_token, when = self._validate_config_checkpoints()
474
+ if stage not in ["build", "upload", "runtime", "any"]:
475
+ raise Exception("Invalid stage provided, must be one of ['build', 'upload', 'runtime']")
476
+ if when != stage and stage != "any":
477
+ logger.info(
478
+ f"Skipping downloading checkpoints for stage {stage} since config.yaml says to download them at stage {when}"
479
+ )
480
+ return path
450
481
 
451
482
  success = True
452
483
  if loader_type == "huggingface":
453
484
  loader = HuggingFaceLoader(repo_id=repo_id, token=hf_token)
454
- path = self._checkpoint_path(
455
- checkpoint_path_override) if checkpoint_path_override else self.checkpoint_path
485
+ # for runtime default to /tmp path
486
+ if stage == "runtime" and checkpoint_path_override is None:
487
+ checkpoint_path_override = self.default_runtime_checkpoint_path()
488
+ path = checkpoint_path_override if checkpoint_path_override else self.checkpoint_path
456
489
  success = loader.download_checkpoints(path)
457
490
 
458
491
  if loader_type:
@@ -461,7 +494,7 @@ class ModelBuilder:
461
494
  sys.exit(1)
462
495
  else:
463
496
  logger.info(f"Downloaded checkpoints for model {repo_id}")
464
- return success
497
+ return path
465
498
 
466
499
  def _concepts_protos_from_concepts(self, concepts):
467
500
  concept_protos = []
@@ -520,11 +553,12 @@ class ModelBuilder:
520
553
  self._concepts_protos_from_concepts(labels))
521
554
  return model_version_proto
522
555
 
523
- def upload_model_version(self, download_checkpoints):
556
+ def upload_model_version(self):
524
557
  file_path = f"{self.folder}.tar.gz"
525
558
  logger.debug(f"Will tar it into file: {file_path}")
526
559
 
527
560
  model_type_id = self.config.get('model').get('model_type_id')
561
+ loader_type, repo_id, hf_token, when = self._validate_config_checkpoints()
528
562
 
529
563
  if (model_type_id in CONCEPTS_REQUIRED_MODEL_TYPE) and 'concepts' not in self.config:
530
564
  logger.info(
@@ -534,15 +568,13 @@ class ModelBuilder:
534
568
  logger.info(
535
569
  "Checkpoints specified in the config.yaml file, will download the HF model's config.json file to infer the concepts."
536
570
  )
537
-
538
- if not download_checkpoints and not HuggingFaceLoader.validate_config(
539
- self.checkpoint_path):
540
-
541
- input(
542
- "Press Enter to download the HuggingFace model's config.json file to infer the concepts and continue..."
543
- )
544
- loader_type, repo_id, hf_token = self._validate_config_checkpoints()
545
- if loader_type == "huggingface":
571
+ # If we don't already have the concepts, download the config.json file from HuggingFace
572
+ if loader_type == "huggingface":
573
+ # If the config.yaml says we'll download in the future (build time or runtime) then we need to get this config now.
574
+ if when != "upload" and not HuggingFaceLoader.validate_config(self.checkpoint_path):
575
+ input(
576
+ "Press Enter to download the HuggingFace model's config.json file to infer the concepts and continue..."
577
+ )
546
578
  loader = HuggingFaceLoader(repo_id=repo_id, token=hf_token)
547
579
  loader.download_config(self.checkpoint_path)
548
580
 
@@ -557,7 +589,7 @@ class ModelBuilder:
557
589
  def filter_func(tarinfo):
558
590
  name = tarinfo.name
559
591
  exclude = [self.tar_file, "*~"]
560
- if not download_checkpoints:
592
+ if when != "upload":
561
593
  exclude.append(self.checkpoint_suffix)
562
594
  return None if any(name.endswith(ex) for ex in exclude) else tarinfo
563
595
 
@@ -569,12 +601,12 @@ class ModelBuilder:
569
601
  logger.debug(f"Size of the tar is: {file_size} bytes")
570
602
 
571
603
  self.storage_request_size = self._get_tar_file_content_size(file_path)
572
- if not download_checkpoints and self.config.get("checkpoints"):
604
+ if when != "upload" and self.config.get("checkpoints"):
573
605
  # Get the checkpoint size to add to the storage request.
574
606
  # First check for the env variable, then try querying huggingface. If all else fails, use the default.
575
607
  checkpoint_size = os.environ.get('CHECKPOINT_SIZE_BYTES', 0)
576
608
  if not checkpoint_size:
577
- _, repo_id, _ = self._validate_config_checkpoints()
609
+ _, repo_id, _, _ = self._validate_config_checkpoints()
578
610
  checkpoint_size = HuggingFaceLoader.get_huggingface_checkpoint_total_size(repo_id)
579
611
  if not checkpoint_size:
580
612
  checkpoint_size = self.DEFAULT_CHECKPOINT_SIZE
@@ -702,10 +734,16 @@ class ModelBuilder:
702
734
  return False
703
735
 
704
736
 
705
- def upload_model(folder, download_checkpoints, skip_dockerfile):
737
+ def upload_model(folder, stage, skip_dockerfile):
738
+ """
739
+ Uploads a model to Clarifai.
740
+
741
+ :param folder: The folder containing the model files.
742
+ :param stage: The stage of when you're uploading this model. This is used to determine when to download the checkpoints based on a match with the "when" field in the config.yaml checkpoints section or if you set stage to "any" it will always download the checkpoints.
743
+ :param skip_dockerfile: If True, skips creating the Dockerfile so you can re-use the local one.
744
+ """
706
745
  builder = ModelBuilder(folder)
707
- if download_checkpoints:
708
- builder.download_checkpoints()
746
+ builder.download_checkpoints(stage=stage)
709
747
  if not skip_dockerfile:
710
748
  builder.create_dockerfile()
711
749
  exists = builder.check_model_exists()
@@ -717,4 +755,4 @@ def upload_model(folder, download_checkpoints, skip_dockerfile):
717
755
  logger.info(f"New model will be created at {builder.model_url} with it's first version.")
718
756
 
719
757
  input("Press Enter to continue...")
720
- builder.upload_model_version(download_checkpoints)
758
+ builder.upload_model_version()
@@ -481,7 +481,8 @@ def main(model_path,
481
481
  )
482
482
  sys.exit(1)
483
483
  manager = ModelRunLocally(model_path)
484
- manager.builder.download_checkpoints()
484
+ # stage="any" forces downloaded now regardless of config.yaml
485
+ manager.builder.download_checkpoints(stage="any")
485
486
  if inside_container:
486
487
  if not manager.is_docker_installed():
487
488
  sys.exit(1)