clarifai 10.8.8__tar.gz → 10.9.0__tar.gz

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 (112) hide show
  1. {clarifai-10.8.8/clarifai.egg-info → clarifai-10.9.0}/PKG-INFO +1 -1
  2. clarifai-10.9.0/clarifai/__init__.py +1 -0
  3. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/deployment.py +12 -0
  4. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/model.py +217 -21
  5. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/nodepool.py +22 -0
  6. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/upload/loaders/imagenet_classification.py +5 -1
  7. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/dockerfile_template/Dockerfile.cpu.template +1 -1
  8. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/dockerfile_template/Dockerfile.cuda.template +7 -57
  9. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/models/model_upload.py +92 -38
  10. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/utils/evaluation/helpers.py +10 -4
  11. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/utils/evaluation/main.py +2 -1
  12. {clarifai-10.8.8 → clarifai-10.9.0/clarifai.egg-info}/PKG-INFO +1 -1
  13. {clarifai-10.8.8 → clarifai-10.9.0}/tests/test_app.py +7 -12
  14. {clarifai-10.8.8 → clarifai-10.9.0}/tests/test_data_upload.py +35 -2
  15. clarifai-10.9.0/tests/test_eval.py +129 -0
  16. clarifai-10.8.8/clarifai/__init__.py +0 -1
  17. clarifai-10.8.8/tests/test_eval.py +0 -90
  18. {clarifai-10.8.8 → clarifai-10.9.0}/LICENSE +0 -0
  19. {clarifai-10.8.8 → clarifai-10.9.0}/MANIFEST.in +0 -0
  20. {clarifai-10.8.8 → clarifai-10.9.0}/README.md +0 -0
  21. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/cli.py +0 -0
  22. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/__init__.py +0 -0
  23. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/app.py +0 -0
  24. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/auth/__init__.py +0 -0
  25. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/auth/helper.py +0 -0
  26. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/auth/register.py +0 -0
  27. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/auth/stub.py +0 -0
  28. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/base.py +0 -0
  29. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/compute_cluster.py +0 -0
  30. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/dataset.py +0 -0
  31. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/input.py +0 -0
  32. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/lister.py +0 -0
  33. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/module.py +0 -0
  34. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/search.py +0 -0
  35. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/user.py +0 -0
  36. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/client/workflow.py +0 -0
  37. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/constants/base.py +0 -0
  38. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/constants/dataset.py +0 -0
  39. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/constants/input.py +0 -0
  40. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/constants/model.py +0 -0
  41. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/constants/rag.py +0 -0
  42. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/constants/search.py +0 -0
  43. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/constants/workflow.py +0 -0
  44. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/__init__.py +0 -0
  45. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/export/__init__.py +0 -0
  46. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/export/inputs_annotations.py +0 -0
  47. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/upload/__init__.py +0 -0
  48. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/upload/base.py +0 -0
  49. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/upload/features.py +0 -0
  50. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/upload/image.py +0 -0
  51. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/upload/loaders/README.md +0 -0
  52. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/upload/loaders/__init__.py +0 -0
  53. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/upload/loaders/coco_captions.py +0 -0
  54. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/upload/loaders/coco_detection.py +0 -0
  55. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/upload/loaders/xview_detection.py +0 -0
  56. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/upload/multimodal.py +0 -0
  57. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/upload/text.py +0 -0
  58. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/datasets/upload/utils.py +0 -0
  59. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/errors.py +0 -0
  60. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/models/__init__.py +0 -0
  61. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/models/api.py +0 -0
  62. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/modules/README.md +0 -0
  63. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/modules/__init__.py +0 -0
  64. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/modules/css.py +0 -0
  65. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/modules/pages.py +0 -0
  66. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/modules/style.css +0 -0
  67. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/rag/__init__.py +0 -0
  68. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/rag/rag.py +0 -0
  69. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/rag/utils.py +0 -0
  70. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/__init__.py +0 -0
  71. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/models/__init__.py +0 -0
  72. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/models/base_typed_model.py +0 -0
  73. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/models/model_class.py +0 -0
  74. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/models/model_runner.py +0 -0
  75. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/models/model_servicer.py +0 -0
  76. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/server.py +0 -0
  77. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/utils/__init__.py +0 -0
  78. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/utils/data_handler.py +0 -0
  79. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/utils/data_utils.py +0 -0
  80. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/utils/loader.py +0 -0
  81. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/runners/utils/url_fetcher.py +0 -0
  82. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/schema/search.py +0 -0
  83. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/urls/helper.py +0 -0
  84. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/utils/__init__.py +0 -0
  85. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/utils/constants.py +0 -0
  86. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/utils/evaluation/__init__.py +0 -0
  87. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/utils/evaluation/testset_annotation_parser.py +0 -0
  88. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/utils/logging.py +0 -0
  89. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/utils/misc.py +0 -0
  90. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/utils/model_train.py +0 -0
  91. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/versions.py +0 -0
  92. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/workflows/__init__.py +0 -0
  93. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/workflows/export.py +0 -0
  94. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/workflows/utils.py +0 -0
  95. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai/workflows/validate.py +0 -0
  96. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai.egg-info/SOURCES.txt +0 -0
  97. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai.egg-info/dependency_links.txt +0 -0
  98. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai.egg-info/entry_points.txt +0 -0
  99. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai.egg-info/requires.txt +0 -0
  100. {clarifai-10.8.8 → clarifai-10.9.0}/clarifai.egg-info/top_level.txt +0 -0
  101. {clarifai-10.8.8 → clarifai-10.9.0}/pyproject.toml +0 -0
  102. {clarifai-10.8.8 → clarifai-10.9.0}/requirements.txt +0 -0
  103. {clarifai-10.8.8 → clarifai-10.9.0}/setup.cfg +0 -0
  104. {clarifai-10.8.8 → clarifai-10.9.0}/setup.py +0 -0
  105. {clarifai-10.8.8 → clarifai-10.9.0}/tests/test_auth.py +0 -0
  106. {clarifai-10.8.8 → clarifai-10.9.0}/tests/test_misc.py +0 -0
  107. {clarifai-10.8.8 → clarifai-10.9.0}/tests/test_model_predict.py +0 -0
  108. {clarifai-10.8.8 → clarifai-10.9.0}/tests/test_model_train.py +0 -0
  109. {clarifai-10.8.8 → clarifai-10.9.0}/tests/test_modules.py +0 -0
  110. {clarifai-10.8.8 → clarifai-10.9.0}/tests/test_rag.py +0 -0
  111. {clarifai-10.8.8 → clarifai-10.9.0}/tests/test_search.py +0 -0
  112. {clarifai-10.8.8 → clarifai-10.9.0}/tests/test_stub.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clarifai
3
- Version: 10.8.8
3
+ Version: 10.9.0
4
4
  Summary: Clarifai Python SDK
5
5
  Home-page: https://github.com/Clarifai/clarifai-python
6
6
  Author: Clarifai
@@ -0,0 +1 @@
1
+ __version__ = "10.9.0"
@@ -39,6 +39,18 @@ class Deployment(Lister, BaseClient):
39
39
  root_certificates_path=root_certificates_path)
40
40
  Lister.__init__(self)
41
41
 
42
+ @staticmethod
43
+ def get_runner_selector(user_id: str, deployment_id: str) -> resources_pb2.RunnerSelector:
44
+ """Returns a RunnerSelector object for the given deployment_id.
45
+
46
+ Args:
47
+ deployment_id (str): The deployment ID for the deployment.
48
+
49
+ Returns:
50
+ resources_pb2.RunnerSelector: A RunnerSelector object for the given deployment_id.
51
+ """
52
+ return resources_pb2.RunnerSelector(deployment_id=deployment_id, user_id=user_id)
53
+
42
54
  def __getattr__(self, name):
43
55
  return getattr(self.deployment_info, name)
44
56
 
@@ -7,7 +7,7 @@ import numpy as np
7
7
  import requests
8
8
  import yaml
9
9
  from clarifai_grpc.grpc.api import resources_pb2, service_pb2
10
- from clarifai_grpc.grpc.api.resources_pb2 import Input
10
+ from clarifai_grpc.grpc.api.resources_pb2 import Input, RunnerSelector
11
11
  from clarifai_grpc.grpc.api.status import status_code_pb2
12
12
  from google.protobuf.json_format import MessageToDict
13
13
  from google.protobuf.struct_pb2 import Struct, Value
@@ -16,8 +16,10 @@ from tqdm import tqdm
16
16
 
17
17
  from clarifai.client.base import BaseClient
18
18
  from clarifai.client.dataset import Dataset
19
+ from clarifai.client.deployment import Deployment
19
20
  from clarifai.client.input import Inputs
20
21
  from clarifai.client.lister import Lister
22
+ from clarifai.client.nodepool import Nodepool
21
23
  from clarifai.constants.model import (CHUNK_SIZE, MAX_CHUNK_SIZE, MAX_MODEL_PREDICT_INPUTS,
22
24
  MAX_RANGE_SIZE, MIN_CHUNK_SIZE, MIN_RANGE_SIZE,
23
25
  MODEL_EXPORT_TIMEOUT, RANGE_SIZE, TRAINABLE_MODEL_TYPES)
@@ -404,11 +406,16 @@ class Model(Lister, BaseClient):
404
406
  model_id=self.id,
405
407
  **dict(self.kwargs, model_version=model_version_info))
406
408
 
407
- def predict(self, inputs: List[Input], inference_params: Dict = {}, output_config: Dict = {}):
409
+ def predict(self,
410
+ inputs: List[Input],
411
+ runner_selector: RunnerSelector = None,
412
+ inference_params: Dict = {},
413
+ output_config: Dict = {}):
408
414
  """Predicts the model based on the given inputs.
409
415
 
410
416
  Args:
411
417
  inputs (list[Input]): The inputs to predict, must be less than 128.
418
+ runner_selector (RunnerSelector): The runner selector to use for the model.
412
419
  """
413
420
  if not isinstance(inputs, list):
414
421
  raise UserError('Invalid inputs, inputs must be a list of Input objects.')
@@ -422,6 +429,7 @@ class Model(Lister, BaseClient):
422
429
  model_id=self.id,
423
430
  version_id=self.model_version.id,
424
431
  inputs=inputs,
432
+ runner_selector=runner_selector,
425
433
  model=self.model_info)
426
434
 
427
435
  start_time = time.time()
@@ -445,6 +453,9 @@ class Model(Lister, BaseClient):
445
453
  def predict_by_filepath(self,
446
454
  filepath: str,
447
455
  input_type: str,
456
+ compute_cluster_id: str = None,
457
+ nodepool_id: str = None,
458
+ deployment_id: str = None,
448
459
  inference_params: Dict = {},
449
460
  output_config: Dict = {}):
450
461
  """Predicts the model based on the given filepath.
@@ -452,6 +463,9 @@ class Model(Lister, BaseClient):
452
463
  Args:
453
464
  filepath (str): The filepath to predict.
454
465
  input_type (str): The type of input. Can be 'image', 'text', 'video' or 'audio.
466
+ compute_cluster_id (str): The compute cluster ID to use for the model.
467
+ nodepool_id (str): The nodepool ID to use for the model.
468
+ deployment_id (str): The deployment ID to use for the model.
455
469
  inference_params (dict): The inference params to override.
456
470
  output_config (dict): The output config to override.
457
471
  min_value (float): The minimum value of the prediction confidence to filter.
@@ -472,11 +486,15 @@ class Model(Lister, BaseClient):
472
486
  with open(filepath, "rb") as f:
473
487
  file_bytes = f.read()
474
488
 
475
- return self.predict_by_bytes(file_bytes, input_type, inference_params, output_config)
489
+ return self.predict_by_bytes(file_bytes, input_type, compute_cluster_id, nodepool_id,
490
+ deployment_id, inference_params, output_config)
476
491
 
477
492
  def predict_by_bytes(self,
478
493
  input_bytes: bytes,
479
494
  input_type: str,
495
+ compute_cluster_id: str = None,
496
+ nodepool_id: str = None,
497
+ deployment_id: str = None,
480
498
  inference_params: Dict = {},
481
499
  output_config: Dict = {}):
482
500
  """Predicts the model based on the given bytes.
@@ -484,6 +502,9 @@ class Model(Lister, BaseClient):
484
502
  Args:
485
503
  input_bytes (bytes): File Bytes to predict on.
486
504
  input_type (str): The type of input. Can be 'image', 'text', 'video' or 'audio.
505
+ compute_cluster_id (str): The compute cluster ID to use for the model.
506
+ nodepool_id (str): The nodepool ID to use for the model.
507
+ deployment_id (str): The deployment ID to use for the model.
487
508
  inference_params (dict): The inference params to override.
488
509
  output_config (dict): The output config to override.
489
510
  min_value (float): The minimum value of the prediction confidence to filter.
@@ -512,12 +533,30 @@ class Model(Lister, BaseClient):
512
533
  elif input_type == "audio":
513
534
  input_proto = Inputs.get_input_from_bytes("", audio_bytes=input_bytes)
514
535
 
536
+ if deployment_id and (compute_cluster_id or nodepool_id):
537
+ raise UserError(
538
+ "You can only specify one of deployment_id or compute_cluster_id and nodepool_id.")
539
+
540
+ runner_selector = None
541
+ if deployment_id:
542
+ runner_selector = Deployment.get_runner_selector(
543
+ user_id=self.user_id, deployment_id=deployment_id)
544
+ elif compute_cluster_id and nodepool_id:
545
+ runner_selector = Nodepool.get_runner_selector(
546
+ user_id=self.user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)
547
+
515
548
  return self.predict(
516
- inputs=[input_proto], inference_params=inference_params, output_config=output_config)
549
+ inputs=[input_proto],
550
+ runner_selector=runner_selector,
551
+ inference_params=inference_params,
552
+ output_config=output_config)
517
553
 
518
554
  def predict_by_url(self,
519
555
  url: str,
520
556
  input_type: str,
557
+ compute_cluster_id: str = None,
558
+ nodepool_id: str = None,
559
+ deployment_id: str = None,
521
560
  inference_params: Dict = {},
522
561
  output_config: Dict = {}):
523
562
  """Predicts the model based on the given URL.
@@ -525,6 +564,9 @@ class Model(Lister, BaseClient):
525
564
  Args:
526
565
  url (str): The URL to predict.
527
566
  input_type (str): The type of input. Can be 'image', 'text', 'video' or 'audio.
567
+ compute_cluster_id (str): The compute cluster ID to use for the model.
568
+ nodepool_id (str): The nodepool ID to use for the model.
569
+ deployment_id (str): The deployment ID to use for the model.
528
570
  inference_params (dict): The inference params to override.
529
571
  output_config (dict): The output config to override.
530
572
  min_value (float): The minimum value of the prediction confidence to filter.
@@ -551,14 +593,43 @@ class Model(Lister, BaseClient):
551
593
  elif input_type == "audio":
552
594
  input_proto = Inputs.get_input_from_url("", audio_url=url)
553
595
 
554
- return self.predict(
555
- inputs=[input_proto], inference_params=inference_params, output_config=output_config)
596
+ if deployment_id and (compute_cluster_id or nodepool_id):
597
+ raise UserError(
598
+ "You can only specify one of deployment_id or compute_cluster_id and nodepool_id.")
599
+
600
+ runner_selector = None
601
+ if deployment_id:
602
+ runner_selector = Deployment.get_runner_selector(
603
+ user_id=self.user_id, deployment_id=deployment_id)
604
+ elif compute_cluster_id and nodepool_id:
605
+ runner_selector = Nodepool.get_runner_selector(
606
+ user_id=self.user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)
556
607
 
557
- def generate(self, inputs: List[Input], inference_params: Dict = {}, output_config: Dict = {}):
608
+ return self.predict(
609
+ inputs=[input_proto],
610
+ runner_selector=runner_selector,
611
+ inference_params=inference_params,
612
+ output_config=output_config)
613
+
614
+ def generate(self,
615
+ inputs: List[Input],
616
+ runner_selector: RunnerSelector = None,
617
+ inference_params: Dict = {},
618
+ output_config: Dict = {}):
558
619
  """Generate the stream output on model based on the given inputs.
559
620
 
560
621
  Args:
561
- inputs (list[Input]): The inputs to predict, must be less than 128.
622
+ inputs (list[Input]): The inputs to generate, must be less than 128.
623
+ runner_selector (RunnerSelector): The runner selector to use for the model.
624
+ inference_params (dict): The inference params to override.
625
+
626
+ Example:
627
+ >>> from clarifai.client.model import Model
628
+ >>> model = Model("url") # Example URL: https://clarifai.com/clarifai/main/models/general-image-recognition
629
+ or
630
+ >>> model = Model(model_id='model_id', user_id='user_id', app_id='app_id')
631
+ >>> stream_response = model.generate(inputs=[input1, input2], runner_selector=runner_selector)
632
+ >>> list_stream_response = [response for response in stream_response]
562
633
  """
563
634
  if not isinstance(inputs, list):
564
635
  raise UserError('Invalid inputs, inputs must be a list of Input objects.')
@@ -572,6 +643,7 @@ class Model(Lister, BaseClient):
572
643
  model_id=self.id,
573
644
  version_id=self.model_version.id,
574
645
  inputs=inputs,
646
+ runner_selector=runner_selector,
575
647
  model=self.model_info)
576
648
 
577
649
  start_time = time.time()
@@ -597,6 +669,9 @@ class Model(Lister, BaseClient):
597
669
  def generate_by_filepath(self,
598
670
  filepath: str,
599
671
  input_type: str,
672
+ compute_cluster_id: str = None,
673
+ nodepool_id: str = None,
674
+ deployment_id: str = None,
600
675
  inference_params: Dict = {},
601
676
  output_config: Dict = {}):
602
677
  """Generate the stream output on model based on the given filepath.
@@ -604,6 +679,9 @@ class Model(Lister, BaseClient):
604
679
  Args:
605
680
  filepath (str): The filepath to predict.
606
681
  input_type (str): The type of input. Can be 'image', 'text', 'video' or 'audio.
682
+ compute_cluster_id (str): The compute cluster ID to use for the model.
683
+ nodepool_id (str): The nodepool ID to use for the model.
684
+ deployment_id (str): The deployment ID to use for the model.
607
685
  inference_params (dict): The inference params to override.
608
686
  output_config (dict): The output config to override.
609
687
  min_value (float): The minimum value of the prediction confidence to filter.
@@ -615,8 +693,7 @@ class Model(Lister, BaseClient):
615
693
  >>> model = Model("url") # Example URL: https://clarifai.com/clarifai/main/models/general-image-recognition
616
694
  or
617
695
  >>> model = Model(model_id='model_id', user_id='user_id', app_id='app_id')
618
- >>> stream_response = model.generate_by_filepath('/path/to/image.jpg', 'image')
619
- >>> stream_response = model.generate_by_filepath('/path/to/text.txt', 'text')
696
+ >>> stream_response = model.generate_by_filepath('/path/to/image.jpg', 'image', deployment_id='deployment_id')
620
697
  >>> list_stream_response = [response for response in stream_response]
621
698
  """
622
699
  if not os.path.isfile(filepath):
@@ -625,11 +702,21 @@ class Model(Lister, BaseClient):
625
702
  with open(filepath, "rb") as f:
626
703
  file_bytes = f.read()
627
704
 
628
- return self.generate_by_bytes(file_bytes, input_type, inference_params, output_config)
705
+ return self.generate_by_bytes(
706
+ filepath=file_bytes,
707
+ input_type=input_type,
708
+ compute_cluster_id=compute_cluster_id,
709
+ nodepool_id=nodepool_id,
710
+ deployment_id=deployment_id,
711
+ inference_params=inference_params,
712
+ output_config=output_config)
629
713
 
630
714
  def generate_by_bytes(self,
631
715
  input_bytes: bytes,
632
716
  input_type: str,
717
+ compute_cluster_id: str = None,
718
+ nodepool_id: str = None,
719
+ deployment_id: str = None,
633
720
  inference_params: Dict = {},
634
721
  output_config: Dict = {}):
635
722
  """Generate the stream output on model based on the given bytes.
@@ -637,6 +724,9 @@ class Model(Lister, BaseClient):
637
724
  Args:
638
725
  input_bytes (bytes): File Bytes to predict on.
639
726
  input_type (str): The type of input. Can be 'image', 'text', 'video' or 'audio.
727
+ compute_cluster_id (str): The compute cluster ID to use for the model.
728
+ nodepool_id (str): The nodepool ID to use for the model.
729
+ deployment_id (str): The deployment ID to use for the model.
640
730
  inference_params (dict): The inference params to override.
641
731
  output_config (dict): The output config to override.
642
732
  min_value (float): The minimum value of the prediction confidence to filter.
@@ -648,6 +738,7 @@ class Model(Lister, BaseClient):
648
738
  >>> model = Model("https://clarifai.com/openai/chat-completion/models/GPT-4")
649
739
  >>> stream_response = model.generate_by_bytes(b'Write a tweet on future of AI',
650
740
  input_type='text',
741
+ deployment_id='deployment_id',
651
742
  inference_params=dict(temperature=str(0.7), max_tokens=30)))
652
743
  >>> list_stream_response = [response for response in stream_response]
653
744
  """
@@ -666,12 +757,30 @@ class Model(Lister, BaseClient):
666
757
  elif input_type == "audio":
667
758
  input_proto = Inputs.get_input_from_bytes("", audio_bytes=input_bytes)
668
759
 
760
+ if deployment_id and (compute_cluster_id or nodepool_id):
761
+ raise UserError(
762
+ "You can only specify one of deployment_id or compute_cluster_id and nodepool_id.")
763
+
764
+ runner_selector = None
765
+ if deployment_id:
766
+ runner_selector = Deployment.get_runner_selector(
767
+ user_id=self.user_id, deployment_id=deployment_id)
768
+ elif compute_cluster_id and nodepool_id:
769
+ runner_selector = Nodepool.get_runner_selector(
770
+ user_id=self.user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)
771
+
669
772
  return self.generate(
670
- inputs=[input_proto], inference_params=inference_params, output_config=output_config)
773
+ inputs=[input_proto],
774
+ runner_selector=runner_selector,
775
+ inference_params=inference_params,
776
+ output_config=output_config)
671
777
 
672
778
  def generate_by_url(self,
673
779
  url: str,
674
780
  input_type: str,
781
+ compute_cluster_id: str = None,
782
+ nodepool_id: str = None,
783
+ deployment_id: str = None,
675
784
  inference_params: Dict = {},
676
785
  output_config: Dict = {}):
677
786
  """Generate the stream output on model based on the given URL.
@@ -679,6 +788,9 @@ class Model(Lister, BaseClient):
679
788
  Args:
680
789
  url (str): The URL to predict.
681
790
  input_type (str): The type of input. Can be 'image', 'text', 'video' or 'audio.
791
+ compute_cluster_id (str): The compute cluster ID to use for the model.
792
+ nodepool_id (str): The nodepool ID to use for the model.
793
+ deployment_id (str): The deployment ID to use for the model.
682
794
  inference_params (dict): The inference params to override.
683
795
  output_config (dict): The output config to override.
684
796
  min_value (float): The minimum value of the prediction confidence to filter.
@@ -690,7 +802,7 @@ class Model(Lister, BaseClient):
690
802
  >>> model = Model("url") # Example URL: https://clarifai.com/clarifai/main/models/general-image-recognition
691
803
  or
692
804
  >>> model = Model(model_id='model_id', user_id='user_id', app_id='app_id')
693
- >>> stream_response = model.generate_by_url('url', 'image')
805
+ >>> stream_response = model.generate_by_url('url', 'image', deployment_id='deployment_id')
694
806
  >>> list_stream_response = [response for response in stream_response]
695
807
  """
696
808
  if input_type not in {'image', 'text', 'video', 'audio'}:
@@ -706,32 +818,58 @@ class Model(Lister, BaseClient):
706
818
  elif input_type == "audio":
707
819
  input_proto = Inputs.get_input_from_url("", audio_url=url)
708
820
 
821
+ if deployment_id and (compute_cluster_id or nodepool_id):
822
+ raise UserError(
823
+ "You can only specify one of deployment_id or compute_cluster_id and nodepool_id.")
824
+
825
+ runner_selector = None
826
+ if deployment_id:
827
+ runner_selector = Deployment.get_runner_selector(
828
+ user_id=self.user_id, deployment_id=deployment_id)
829
+ elif compute_cluster_id and nodepool_id:
830
+ runner_selector = Nodepool.get_runner_selector(
831
+ user_id=self.user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)
832
+
709
833
  return self.generate(
710
- inputs=[input_proto], inference_params=inference_params, output_config=output_config)
834
+ inputs=[input_proto],
835
+ runner_selector=runner_selector,
836
+ inference_params=inference_params,
837
+ output_config=output_config)
711
838
 
712
- def _req_iterator(self, input_iterator: Iterator[List[Input]]):
839
+ def _req_iterator(self, input_iterator: Iterator[List[Input]], runner_selector: RunnerSelector):
713
840
  for inputs in input_iterator:
714
841
  yield service_pb2.PostModelOutputsRequest(
715
842
  user_app_id=self.user_app_id,
716
843
  model_id=self.id,
717
844
  version_id=self.model_version.id,
718
845
  inputs=inputs,
846
+ runner_selector=runner_selector,
719
847
  model=self.model_info)
720
848
 
721
849
  def stream(self,
722
850
  inputs: Iterator[List[Input]],
851
+ runner_selector: RunnerSelector = None,
723
852
  inference_params: Dict = {},
724
853
  output_config: Dict = {}):
725
854
  """Generate the stream output on model based on the given stream of inputs.
726
855
 
727
856
  Args:
728
857
  inputs (Iterator[list[Input]]): stream of inputs to predict, must be less than 128.
858
+ runner_selector (RunnerSelector): The runner selector to use for the model.
859
+
860
+ Example:
861
+ >>> from clarifai.client.model import Model
862
+ >>> model = Model("url") # Example URL: https://clarifai.com/clarifai/main/models/general-image-recognition
863
+ or
864
+ >>> model = Model(model_id='model_id', user_id='user_id', app_id='app_id')
865
+ >>> stream_response = model.stream(inputs=inputs, runner_selector=runner_selector)
866
+ >>> list_stream_response = [response for response in stream_response]
729
867
  """
730
868
  # if not isinstance(inputs, Iterator[List[Input]]):
731
869
  # raise UserError('Invalid inputs, inputs must be a iterator of list of Input objects.')
732
870
 
733
871
  self._override_model_version(inference_params, output_config)
734
- request = self._req_iterator(inputs)
872
+ request = self._req_iterator(inputs, runner_selector)
735
873
 
736
874
  start_time = time.time()
737
875
  backoff_iterator = BackoffIterator(10)
@@ -756,6 +894,9 @@ class Model(Lister, BaseClient):
756
894
  def stream_by_filepath(self,
757
895
  filepath: str,
758
896
  input_type: str,
897
+ compute_cluster_id: str = None,
898
+ nodepool_id: str = None,
899
+ deployment_id: str = None,
759
900
  inference_params: Dict = {},
760
901
  output_config: Dict = {}):
761
902
  """Stream the model output based on the given filepath.
@@ -763,6 +904,9 @@ class Model(Lister, BaseClient):
763
904
  Args:
764
905
  filepath (str): The filepath to predict.
765
906
  input_type (str): The type of input. Can be 'image', 'text', 'video' or 'audio.
907
+ compute_cluster_id (str): The compute cluster ID to use for the model.
908
+ nodepool_id (str): The nodepool ID to use for the model.
909
+ deployment_id (str): The deployment ID to use for the model.
766
910
  inference_params (dict): The inference params to override.
767
911
  output_config (dict): The output config to override.
768
912
  min_value (float): The minimum value of the prediction confidence to filter.
@@ -772,7 +916,7 @@ class Model(Lister, BaseClient):
772
916
  Example:
773
917
  >>> from clarifai.client.model import Model
774
918
  >>> model = Model("url")
775
- >>> stream_response = model.stream_by_filepath('/path/to/image.jpg', 'image')
919
+ >>> stream_response = model.stream_by_filepath('/path/to/image.jpg', 'image', deployment_id='deployment_id')
776
920
  >>> list_stream_response = [response for response in stream_response]
777
921
  """
778
922
  if not os.path.isfile(filepath):
@@ -781,11 +925,21 @@ class Model(Lister, BaseClient):
781
925
  with open(filepath, "rb") as f:
782
926
  file_bytes = f.read()
783
927
 
784
- return self.stream_by_bytes(iter([file_bytes]), input_type, inference_params, output_config)
928
+ return self.stream_by_bytes(
929
+ input_bytes_iterator=iter([file_bytes]),
930
+ input_type=input_type,
931
+ compute_cluster_id=compute_cluster_id,
932
+ nodepool_id=nodepool_id,
933
+ deployment_id=deployment_id,
934
+ inference_params=inference_params,
935
+ output_config=output_config)
785
936
 
786
937
  def stream_by_bytes(self,
787
938
  input_bytes_iterator: Iterator[bytes],
788
939
  input_type: str,
940
+ compute_cluster_id: str = None,
941
+ nodepool_id: str = None,
942
+ deployment_id: str = None,
789
943
  inference_params: Dict = {},
790
944
  output_config: Dict = {}):
791
945
  """Stream the model output based on the given bytes.
@@ -793,6 +947,9 @@ class Model(Lister, BaseClient):
793
947
  Args:
794
948
  input_bytes_iterator (Iterator[bytes]): Iterator of file bytes to predict on.
795
949
  input_type (str): The type of input. Can be 'image', 'text', 'video' or 'audio.
950
+ compute_cluster_id (str): The compute cluster ID to use for the model.
951
+ nodepool_id (str): The nodepool ID to use for the model.
952
+ deployment_id (str): The deployment ID to use for the model.
796
953
  inference_params (dict): The inference params to override.
797
954
  output_config (dict): The output config to override.
798
955
  min_value (float): The minimum value of the prediction confidence to filter.
@@ -804,6 +961,7 @@ class Model(Lister, BaseClient):
804
961
  >>> model = Model("https://clarifai.com/openai/chat-completion/models/GPT-4")
805
962
  >>> stream_response = model.stream_by_bytes(iter([b'Write a tweet on future of AI']),
806
963
  input_type='text',
964
+ deployment_id='deployment_id',
807
965
  inference_params=dict(temperature=str(0.7), max_tokens=30)))
808
966
  >>> list_stream_response = [response for response in stream_response]
809
967
  """
@@ -822,11 +980,30 @@ class Model(Lister, BaseClient):
822
980
  elif input_type == "audio":
823
981
  yield [Inputs.get_input_from_bytes("", audio_bytes=input_bytes)]
824
982
 
825
- return self.stream(input_generator(), inference_params, output_config)
983
+ if deployment_id and (compute_cluster_id or nodepool_id):
984
+ raise UserError(
985
+ "You can only specify one of deployment_id or compute_cluster_id and nodepool_id.")
986
+
987
+ runner_selector = None
988
+ if deployment_id:
989
+ runner_selector = Deployment.get_runner_selector(
990
+ user_id=self.user_id, deployment_id=deployment_id)
991
+ elif compute_cluster_id and nodepool_id:
992
+ runner_selector = Nodepool.get_runner_selector(
993
+ user_id=self.user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)
994
+
995
+ return self.stream(
996
+ inputs=input_generator(),
997
+ runner_selector=runner_selector,
998
+ inference_params=inference_params,
999
+ output_config=output_config)
826
1000
 
827
1001
  def stream_by_url(self,
828
1002
  url_iterator: Iterator[str],
829
1003
  input_type: str,
1004
+ compute_cluster_id: str = None,
1005
+ nodepool_id: str = None,
1006
+ deployment_id: str = None,
830
1007
  inference_params: Dict = {},
831
1008
  output_config: Dict = {}):
832
1009
  """Stream the model output based on the given URL.
@@ -834,6 +1011,9 @@ class Model(Lister, BaseClient):
834
1011
  Args:
835
1012
  url_iterator (Iterator[str]): Iterator of URLs to predict.
836
1013
  input_type (str): The type of input. Can be 'image', 'text', 'video' or 'audio.
1014
+ compute_cluster_id (str): The compute cluster ID to use for the model.
1015
+ nodepool_id (str): The nodepool ID to use for the model.
1016
+ deployment_id (str): The deployment ID to use for the model.
837
1017
  inference_params (dict): The inference params to override.
838
1018
  output_config (dict): The output config to override.
839
1019
  min_value (float): The minimum value of the prediction confidence to filter.
@@ -843,7 +1023,7 @@ class Model(Lister, BaseClient):
843
1023
  Example:
844
1024
  >>> from clarifai.client.model import Model
845
1025
  >>> model = Model("url")
846
- >>> stream_response = model.stream_by_url(iter(['url']), 'image')
1026
+ >>> stream_response = model.stream_by_url(iter(['url']), 'image', deployment_id='deployment_id')
847
1027
  >>> list_stream_response = [response for response in stream_response]
848
1028
  """
849
1029
  if input_type not in {'image', 'text', 'video', 'audio'}:
@@ -861,7 +1041,23 @@ class Model(Lister, BaseClient):
861
1041
  elif input_type == "audio":
862
1042
  yield [Inputs.get_input_from_url("", audio_url=url)]
863
1043
 
864
- return self.stream(input_generator(), inference_params, output_config)
1044
+ if deployment_id and (compute_cluster_id or nodepool_id):
1045
+ raise UserError(
1046
+ "You can only specify one of deployment_id or compute_cluster_id and nodepool_id.")
1047
+
1048
+ runner_selector = None
1049
+ if deployment_id:
1050
+ runner_selector = Deployment.get_runner_selector(
1051
+ user_id=self.user_id, deployment_id=deployment_id)
1052
+ elif compute_cluster_id and nodepool_id:
1053
+ runner_selector = Nodepool.get_runner_selector(
1054
+ user_id=self.user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)
1055
+
1056
+ return self.stream(
1057
+ inputs=input_generator(),
1058
+ runner_selector=runner_selector,
1059
+ inference_params=inference_params,
1060
+ output_config=output_config)
865
1061
 
866
1062
  def _override_model_version(self, inference_params: Dict = {}, output_config: Dict = {}) -> None:
867
1063
  """Overrides the model version.
@@ -114,6 +114,28 @@ class Nodepool(Lister, BaseClient):
114
114
  deployment["visibility"] = resources_pb2.Visibility(**deployment["visibility"])
115
115
  return deployment
116
116
 
117
+ @staticmethod
118
+ def get_runner_selector(user_id: str, compute_cluster_id: str,
119
+ nodepool_id: str) -> resources_pb2.RunnerSelector:
120
+ """Returns a RunnerSelector object for the specified compute cluster and nodepool.
121
+
122
+ Args:
123
+ user_id (str): The user ID of the user.
124
+ compute_cluster_id (str): The compute cluster ID for the compute cluster.
125
+ nodepool_id (str): The nodepool ID for the nodepool.
126
+
127
+ Returns:
128
+ resources_pb2.RunnerSelector: A RunnerSelector object for the specified compute cluster and nodepool.
129
+
130
+ Example:
131
+ >>> from clarifai.client.nodepool import Nodepool
132
+ >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
133
+ >>> runner_selector = Nodepool.get_runner_selector(user_id="user_id", compute_cluster_id="compute_cluster_id", nodepool_id="nodepool_id")
134
+ """
135
+ compute_cluster = resources_pb2.ComputeCluster(id=compute_cluster_id, user_id=user_id)
136
+ nodepool = resources_pb2.Nodepool(id=nodepool_id, compute_cluster=compute_cluster)
137
+ return resources_pb2.RunnerSelector(nodepool=nodepool)
138
+
117
139
  def create_deployment(self, deployment_id: str, config_filepath: str) -> Deployment:
118
140
  """Creates a deployment for the nodepool.
119
141
 
@@ -24,6 +24,10 @@ class ImageNetDataLoader(ClarifaiDataLoader):
24
24
 
25
25
  self.load_data()
26
26
 
27
+ @property
28
+ def task(self):
29
+ return "visual_classification"
30
+
27
31
  def load_data(self):
28
32
  #Creating label map
29
33
  with open(os.path.join(self.data_dir, "LOC_synset_mapping.txt")) as _file:
@@ -54,5 +58,5 @@ class ImageNetDataLoader(ClarifaiDataLoader):
54
58
  def __getitem__(self, idx):
55
59
  return VisualClassificationFeatures(
56
60
  image_path=self.image_paths[idx],
57
- label=self.concepts[idx],
61
+ labels=self.concepts[idx],
58
62
  id=self.image_paths[idx].split('.')[0].split('/')[-1])
@@ -1,5 +1,5 @@
1
1
  ARG PYTHON_VERSION=${PYTHON_VERSION}
2
- FROM public.ecr.aws/docker/library/python:${PYTHON_VERSION}-slim as build
2
+ FROM public.ecr.aws/docker/library/python:${PYTHON_VERSION}-slim-bookworm as build
3
3
 
4
4
  # Set the working directory to /app
5
5
  WORKDIR /app