google-cloud-pipeline-components 2.10.0__py3-none-any.whl → 2.12.0__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.

Potentially problematic release.


This version of google-cloud-pipeline-components might be problematic. Click here for more details.

Files changed (43) hide show
  1. google_cloud_pipeline_components/_implementation/llm/batch_prediction_pairwise.py +14 -4
  2. google_cloud_pipeline_components/_implementation/llm/bulk_inferrer.py +7 -0
  3. google_cloud_pipeline_components/_implementation/llm/deployment_graph.py +6 -1
  4. google_cloud_pipeline_components/_implementation/llm/function_based.py +74 -168
  5. google_cloud_pipeline_components/_implementation/llm/generated/refined_image_versions.py +1 -1
  6. google_cloud_pipeline_components/_implementation/llm/model_evaluation_text_generation_pairwise.py +45 -3
  7. google_cloud_pipeline_components/_implementation/llm/online_evaluation_pairwise.py +14 -2
  8. google_cloud_pipeline_components/_implementation/llm/private_text_comparison_importer.py +9 -2
  9. google_cloud_pipeline_components/_implementation/llm/private_text_importer.py +8 -1
  10. google_cloud_pipeline_components/_implementation/llm/reinforcement_learning_graph.py +14 -28
  11. google_cloud_pipeline_components/_implementation/llm/reinforcer.py +13 -0
  12. google_cloud_pipeline_components/_implementation/llm/reward_model_graph.py +36 -27
  13. google_cloud_pipeline_components/_implementation/llm/reward_model_trainer.py +17 -0
  14. google_cloud_pipeline_components/_implementation/llm/rlhf_preprocessor.py +60 -0
  15. google_cloud_pipeline_components/_implementation/llm/supervised_fine_tuner.py +1 -0
  16. google_cloud_pipeline_components/_implementation/llm/utils.py +25 -2
  17. google_cloud_pipeline_components/_implementation/llm/validate_pipeline.py +113 -0
  18. google_cloud_pipeline_components/_implementation/model_evaluation/__init__.py +2 -0
  19. google_cloud_pipeline_components/_implementation/model_evaluation/endpoint_batch_predict/component.py +1 -1
  20. google_cloud_pipeline_components/_implementation/model_evaluation/llm_evaluation/component.py +2 -2
  21. google_cloud_pipeline_components/_implementation/model_evaluation/llm_evaluation_preprocessor/component.py +2 -2
  22. google_cloud_pipeline_components/_implementation/model_evaluation/model_name_preprocessor/__init__.py +14 -0
  23. google_cloud_pipeline_components/_implementation/model_evaluation/model_name_preprocessor/component.py +74 -0
  24. google_cloud_pipeline_components/_implementation/model_evaluation/version.py +1 -1
  25. google_cloud_pipeline_components/container/_implementation/model_evaluation/import_model_evaluation.py +7 -7
  26. google_cloud_pipeline_components/preview/llm/infer/__init__.py +13 -0
  27. google_cloud_pipeline_components/preview/llm/infer/component.py +10 -10
  28. google_cloud_pipeline_components/preview/llm/rlaif/component.py +10 -3
  29. google_cloud_pipeline_components/preview/llm/rlhf/component.py +43 -22
  30. google_cloud_pipeline_components/preview/model_evaluation/__init__.py +2 -2
  31. google_cloud_pipeline_components/preview/model_evaluation/model_based_llm_evaluation/autosxs/autosxs_pipeline.py +45 -3
  32. google_cloud_pipeline_components/proto/preflight_validations_pb2.py +19 -30
  33. google_cloud_pipeline_components/v1/custom_job/utils.py +22 -22
  34. google_cloud_pipeline_components/v1/model/get_model/component.py +1 -1
  35. google_cloud_pipeline_components/v1/model_evaluation/__init__.py +4 -0
  36. google_cloud_pipeline_components/{preview → v1}/model_evaluation/evaluation_llm_classification_pipeline.py +14 -2
  37. google_cloud_pipeline_components/{preview → v1}/model_evaluation/evaluation_llm_text_generation_pipeline.py +29 -17
  38. google_cloud_pipeline_components/version.py +1 -1
  39. {google_cloud_pipeline_components-2.10.0.dist-info → google_cloud_pipeline_components-2.12.0.dist-info}/METADATA +1 -2
  40. {google_cloud_pipeline_components-2.10.0.dist-info → google_cloud_pipeline_components-2.12.0.dist-info}/RECORD +43 -39
  41. {google_cloud_pipeline_components-2.10.0.dist-info → google_cloud_pipeline_components-2.12.0.dist-info}/WHEEL +1 -1
  42. {google_cloud_pipeline_components-2.10.0.dist-info → google_cloud_pipeline_components-2.12.0.dist-info}/LICENSE +0 -0
  43. {google_cloud_pipeline_components-2.10.0.dist-info → google_cloud_pipeline_components-2.12.0.dist-info}/top_level.txt +0 -0
@@ -51,6 +51,9 @@ def batch_prediction_pairwise(
51
51
  model_b_parameters: Dict[str, str] = {},
52
52
  human_preference_column: str = '',
53
53
  experimental_args: Dict[str, Any] = {},
54
+ project: str = _placeholders.PROJECT_ID_PLACEHOLDER,
55
+ location: str = _placeholders.LOCATION_PLACEHOLDER,
56
+ encryption_spec_key_name: str = '',
54
57
  ) -> dsl.ContainerSpec: # pylint: disable=g-doc-args
55
58
  """Runs up to two LLM Batch Prediction jobs side-by-side.
56
59
 
@@ -83,6 +86,11 @@ def batch_prediction_pairwise(
83
86
  human_preference_column: The column containing ground truths. The default
84
87
  value is an empty string if not be provided by users.
85
88
  experimental_args: Experimentally released arguments. Subject to change.
89
+ project: Project used to run batch prediction jobs.
90
+ location: Location used to run batch prediction jobs.
91
+ encryption_spec_key_name: Customer-managed encryption key options. If this
92
+ is set, then all resources created by the component will be encrypted with
93
+ the provided encryption key.
86
94
 
87
95
  Returns:
88
96
  preprocessed_evaluation_dataset: Dataset of the table containing the inputs
@@ -94,8 +102,8 @@ def batch_prediction_pairwise(
94
102
  metadata for the task preprocess component.
95
103
  """
96
104
  return gcpc_utils.build_serverless_customjob_container_spec(
97
- project=_placeholders.PROJECT_ID_PLACEHOLDER,
98
- location=_placeholders.LOCATION_PLACEHOLDER,
105
+ project=project,
106
+ location=location,
99
107
  custom_job_payload=utils.build_payload(
100
108
  display_name='batch_prediction_pairwise',
101
109
  machine_type='n1-standard-4',
@@ -110,8 +118,8 @@ def batch_prediction_pairwise(
110
118
  "{{$.inputs.parameters['id_columns'].json_escape[0]}}"
111
119
  ),
112
120
  f'--task={task}',
113
- f'--project={_placeholders.PROJECT_ID_PLACEHOLDER}',
114
- f'--location={_placeholders.LOCATION_PLACEHOLDER}',
121
+ f'--project={project}',
122
+ f'--location={location}',
115
123
  f'--model_a={model_a}',
116
124
  f'--model_b={model_b}',
117
125
  (
@@ -147,9 +155,11 @@ def batch_prediction_pairwise(
147
155
  f'--staging_dir={dsl.PIPELINE_ROOT_PLACEHOLDER}',
148
156
  f'--preprocessed_evaluation_dataset_uri={preprocessed_evaluation_dataset_uri}',
149
157
  f'--metadata_path={metadata}',
158
+ f'--kms_key_name={encryption_spec_key_name}',
150
159
  f'--gcp_resources_path={gcp_resources}',
151
160
  '--executor_input={{$.json_escape[1]}}',
152
161
  ],
162
+ encryption_spec_key_name=encryption_spec_key_name,
153
163
  ),
154
164
  gcp_resources=gcp_resources,
155
165
  )
@@ -37,6 +37,7 @@ def bulk_inferrer(
37
37
  output_prediction_gcs_path: kfp.dsl.OutputPath(str), # pytype: disable=invalid-annotation
38
38
  gcp_resources: kfp.dsl.OutputPath(str), # pytype: disable=invalid-annotation
39
39
  sampling_strategy: str = 'greedy',
40
+ encryption_spec_key_name: str = '',
40
41
  ) -> kfp.dsl.ContainerSpec: # pylint: disable=g-doc-args
41
42
  """Performs bulk inference.
42
43
 
@@ -56,6 +57,10 @@ def bulk_inferrer(
56
57
  input_dataset_path: Path to dataset to use for inference.
57
58
  sampling_strategy: The sampling strategy for inference.
58
59
  dataset_split: Perform inference on this split of the input dataset.
60
+ encryption_spec_key_name: Customer-managed encryption key. If this is set,
61
+ then all resources created by the CustomJob will be encrypted with the
62
+ provided encryption key. Note that this is not supported for TPU at the
63
+ moment.
59
64
 
60
65
  Returns:
61
66
  output_prediction: Where to save the output prediction.
@@ -72,6 +77,7 @@ def bulk_inferrer(
72
77
  machine_type=machine_type,
73
78
  image_uri=image_uri,
74
79
  args=[
80
+ '--app_name=bulk_inferrer',
75
81
  f'--input_model={input_model}',
76
82
  f'--input_dataset={input_dataset_path}',
77
83
  f'--dataset_split={dataset_split}',
@@ -82,6 +88,7 @@ def bulk_inferrer(
82
88
  f'--output_prediction={output_prediction}',
83
89
  f'--output_prediction_gcs_path={output_prediction_gcs_path}',
84
90
  ],
91
+ encryption_spec_key_name=encryption_spec_key_name,
85
92
  ),
86
93
  gcp_resources=gcp_resources,
87
94
  )
@@ -36,6 +36,8 @@ def pipeline(
36
36
  large_model_reference: str,
37
37
  model_display_name: Optional[str] = None,
38
38
  deploy_model: bool = True,
39
+ encryption_spec_key_name: str = '',
40
+ upload_location: str = _placeholders.LOCATION_PLACEHOLDER,
39
41
  ) -> PipelineOutput:
40
42
  # fmt: off
41
43
  """Uploads a tuned language model and (optionally) deploys it to an endpoint.
@@ -45,13 +47,14 @@ def pipeline(
45
47
  large_model_reference: Name of the base model. Supported values are `text-bison@001`, `t5-small`, `t5-large`, `t5-xl` and `t5-xxl`. `text-bison@001` and `t5-small` are supported in `us-central1` and `europe-west4`. `t5-large`, `t5-xl` and `t5-xxl` are only supported in `europe-west4`.
46
48
  model_display_name: Name of the fine-tuned model shown in the Model Registry. If not provided, a default name will be created.
47
49
  deploy_model: Whether to deploy the model to an endpoint in `us-central1`. Default is True.
50
+ encryption_spec_key_name: Customer-managed encryption key. If this is set, then all resources created by the CustomJob will be encrypted with the provided encryption key. Note that this is not supported for TPU at the moment.
51
+ upload_location: Region to upload and deploy the model to. Default is the location used to run the pipeline components.
48
52
 
49
53
  Returns:
50
54
  model_resource_name: Path to the model uploaded to the Model Registry. This will be an empty string if the model was not deployed.
51
55
  endpoint_resource_name: Path the Online Prediction Endpoint. This will be an empty string if the model was not deployed.
52
56
  """
53
57
  # fmt: on
54
- upload_location = 'us-central1'
55
58
  adapter_artifact = kfp.dsl.importer(
56
59
  artifact_uri=output_adapter_path,
57
60
  artifact_class=kfp.dsl.Artifact,
@@ -87,6 +90,7 @@ def pipeline(
87
90
  model_display_name=display_name.output,
88
91
  model_reference_name=large_model_reference,
89
92
  upload_model=upload_model.output,
93
+ encryption_spec_key_name=encryption_spec_key_name,
90
94
  tune_type='rlhf',
91
95
  ).set_display_name('Upload Model')
92
96
  deploy_model = function_based.resolve_deploy_model(
@@ -102,6 +106,7 @@ def pipeline(
102
106
  display_name=display_name.output,
103
107
  regional_endpoint=regional_endpoint.output,
104
108
  deploy_model=deploy_model.output,
109
+ encryption_spec_key_name=encryption_spec_key_name,
105
110
  ).set_display_name('Deploy Model')
106
111
  return PipelineOutput(
107
112
  model_resource_name=upload_task.outputs['model_resource_name'],
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
  """Python function-based components used in KFP pipelies."""
15
15
  import functools
16
- from typing import Any, Dict, List, NamedTuple, Optional
16
+ from typing import List, NamedTuple, Optional
17
17
 
18
18
  from google_cloud_pipeline_components import _image
19
19
  from google_cloud_pipeline_components._implementation.llm import env
@@ -22,19 +22,27 @@ from kfp import dsl
22
22
 
23
23
  @dsl.component(base_image=_image.GCPC_IMAGE_TAG, install_kfp_package=False)
24
24
  def resolve_machine_spec(
25
- location: str,
25
+ accelerator_type: str = 'GPU',
26
26
  use_test_spec: bool = False,
27
27
  ) -> NamedTuple(
28
- 'MachineSpec', machine_type=str, accelerator_type=str, accelerator_count=int
28
+ 'MachineSpec',
29
+ machine_type=str,
30
+ tuning_location=str,
31
+ accelerator_type=str,
32
+ accelerator_count=int,
29
33
  ):
30
- """Returns machine spec to use for a given location.
34
+ """Returns machine spec to use for a given accelerator_type.
31
35
 
32
36
  Args:
33
- location: Where the machine will run.
34
- use_test_spec: Whether to use a lower resource machine for testing.
37
+ accelerator_type: One of 'TPU' or 'GPU'. If 'TPU' is specified, tuning
38
+ components run in europe-west4. Otherwise tuning components run in
39
+ us-central1 on GPUs. Default is 'GPU'.
40
+ use_test_spec: Whether to use a lower resource machine for testing. If True,
41
+ a machine with the specified `accelerator_type` is provisioned.
35
42
 
36
43
  Returns:
37
44
  Machine spec.
45
+ tuning_location: Where the machine will run.
38
46
 
39
47
  Raises:
40
48
  ValueError: If accelerators are requested in an unsupported location.
@@ -42,57 +50,78 @@ def resolve_machine_spec(
42
50
  outputs = NamedTuple(
43
51
  'MachineSpec',
44
52
  machine_type=str,
45
- accelerator_type=str,
46
53
  accelerator_count=int,
54
+ tuning_location=str,
55
+ accelerator_type=str,
47
56
  )
48
- tpu_regions = {'europe-west4'}
49
- gpu_regions = {'us-central1'}
50
57
  if use_test_spec:
51
- return outputs(
52
- machine_type='a2-highgpu-1g',
53
- accelerator_type='NVIDIA_TESLA_A100',
54
- accelerator_count=1,
55
- )
56
- elif location in tpu_regions:
58
+ if accelerator_type == 'TPU':
59
+ return outputs(
60
+ machine_type='cloud-tpu',
61
+ accelerator_type='TPU_V3',
62
+ accelerator_count=32,
63
+ tuning_location='europe-west4',
64
+ )
65
+ elif accelerator_type == 'GPU':
66
+ return outputs(
67
+ machine_type='a2-highgpu-1g',
68
+ accelerator_type='NVIDIA_TESLA_A100',
69
+ accelerator_count=1,
70
+ tuning_location='us-central1',
71
+ )
72
+ elif accelerator_type == 'CPU':
73
+ return outputs(
74
+ machine_type='e2-standard-16',
75
+ accelerator_type='ACCELERATOR_TYPE_UNSPECIFIED',
76
+ accelerator_count=0,
77
+ tuning_location='us-central1',
78
+ )
79
+ else:
80
+ raise ValueError(
81
+ f'Unsupported test accelerator_type {accelerator_type}. Must be one '
82
+ 'of TPU, GPU or CPU.'
83
+ )
84
+
85
+ if accelerator_type == 'TPU':
57
86
  return outputs(
58
87
  machine_type='cloud-tpu',
59
88
  accelerator_type='TPU_V3',
60
89
  accelerator_count=64,
90
+ tuning_location='europe-west4',
61
91
  )
62
- elif location in gpu_regions:
92
+ elif accelerator_type == 'GPU':
63
93
  return outputs(
64
94
  machine_type='a2-ultragpu-8g',
65
95
  accelerator_type='NVIDIA_A100_80GB',
66
96
  accelerator_count=8,
97
+ tuning_location='us-central1',
98
+ )
99
+ else:
100
+ raise ValueError(
101
+ f'Unsupported accelerator_type {accelerator_type}. Must be one of'
102
+ 'TPU or GPU.'
67
103
  )
68
- raise ValueError(
69
- f'Unsupported accelerator location {location}. Must be one of'
70
- f' {tpu_regions | gpu_regions}.'
71
- )
72
104
 
73
105
 
74
106
  @dsl.component(base_image=_image.GCPC_IMAGE_TAG, install_kfp_package=False)
75
- def resolve_image_uri(
76
- image_name: str,
107
+ def resolve_refined_image_uri(
77
108
  project: str,
78
109
  location: str,
79
110
  artifact_registry: str,
80
- image_name_prefix: str,
81
111
  tag: str,
82
112
  accelerator_type: str = '',
83
- accelerator_count: int = 0,
113
+ use_experimental_image: bool = False,
84
114
  ) -> str:
85
115
  """Generates image uri based on base image name and accelerator type.
86
116
 
87
117
  Args:
88
- image_name: Base image name, e.g. ``'sft'`` or ``'reward_model'``.
89
118
  project: Project that contains the artifact registry.
90
119
  location: Region that contains the artifact registry.
91
120
  artifact_registry: Registry that contains Docker images.
92
- image_name_prefix: Text to prepend to the base image name.
93
121
  tag: Image tag.
94
122
  accelerator_type: One of the supported accelerator types, e.g. ``'TPU_V3'``.
95
- accelerator_count: Number of accelerators.
123
+ use_experimental_image: Whether to use refined experimental image. Default
124
+ is False.
96
125
 
97
126
  Returns:
98
127
  Docker image uri
@@ -100,61 +129,36 @@ def resolve_image_uri(
100
129
  Raises:
101
130
  ValueError: if an unsupported accelerator type is provided.
102
131
  """
103
- cpu_only_images = {
104
- 'text_importer',
105
- 'text_comparison_importer',
106
- }
107
-
108
- if image_name in cpu_only_images:
109
- accelerator_postfix = ''
110
- elif accelerator_type == 'TPU_V3':
111
- accelerator_postfix = '_tpu'
112
- elif accelerator_type == 'NVIDIA_A100_80GB' and accelerator_count == 8:
113
- accelerator_postfix = '_gpu_test'
132
+ if not accelerator_type or accelerator_type == 'ACCELERATOR_TYPE_UNSPECIFIED':
133
+ accelerator_postfix = 'cpu'
134
+ elif 'TPU' in accelerator_type:
135
+ accelerator_postfix = 'tpu'
136
+ elif 'A100' in accelerator_type:
137
+ accelerator_postfix = 'gpu'
114
138
  else:
115
- accelerator_postfix = '_gpu'
116
-
117
- backup_images = {
118
- 'sft',
119
- 'reward_model',
120
- 'reinforcer',
121
- 'infer',
122
- 'text_importer',
123
- 'text_comparison_importer',
124
- }
125
- if image_name in backup_images and accelerator_postfix != '_gpu_test':
126
- accelerator_postfix += '_backup'
127
- return f'{location}-docker.pkg.dev/{project}/{artifact_registry}/{image_name_prefix}{image_name}{accelerator_postfix}:{tag}'
139
+ raise ValueError(
140
+ f'Unsupported accelerator type {accelerator_type}. Must a TPU, an A100'
141
+ 'variant or empty if using a CPU-only machine.'
142
+ )
143
+
144
+ image_name_prefix = 'refined_'
145
+ if use_experimental_image:
146
+ image_name_prefix += 'experimental_'
147
+
148
+ return f'{location}-docker.pkg.dev/{project}/{artifact_registry}/{image_name_prefix}{accelerator_postfix}:{tag}'
128
149
 
129
150
 
130
151
  # Resolves image uri from the environment's private artifact registry.
131
152
  # By default this resolves an image in the vertex private registry.
132
- resolve_private_image_uri = functools.partial(
133
- resolve_image_uri,
153
+ resolve_private_refined_image_uri = functools.partial(
154
+ resolve_refined_image_uri,
134
155
  project=env.PRIVATE_ARTIFACT_REGISTRY_PROJECT,
135
156
  location=env.PRIVATE_ARTIFACT_REGISTRY_LOCATION,
136
157
  artifact_registry=env.PRIVATE_ARTIFACT_REGISTRY,
137
- image_name_prefix=env.PRIVATE_IMAGE_NAME_PREFIX,
138
158
  tag=env.get_private_image_tag(),
139
159
  )
140
160
 
141
161
 
142
- @dsl.component(base_image=_image.GCPC_IMAGE_TAG, install_kfp_package=False)
143
- def resolve_data_paths(
144
- input_dataset: str,
145
- ) -> NamedTuple('DataPaths', tfds_data_dir=str, tfds_name=str):
146
- """Resolves dataset paths needed by downstream components."""
147
- # pylint: disable=g-import-not-at-top,import-outside-toplevel,redefined-outer-name,reimported
148
- import os
149
- # pylint: enable=g-import-not-at-top,import-outside-toplevel,redefined-outer-name,reimported
150
- outputs = NamedTuple('DataPaths', tfds_data_dir=str, tfds_name=str)
151
- tfds_data_dir, tfds_name = os.path.split(input_dataset)
152
- return outputs(
153
- tfds_data_dir=tfds_data_dir,
154
- tfds_name=tfds_name,
155
- )
156
-
157
-
158
162
  @dsl.component(base_image=_image.GCPC_IMAGE_TAG, install_kfp_package=False)
159
163
  def resolve_reference_model_metadata(
160
164
  large_model_reference: str,
@@ -461,14 +465,6 @@ def value_exists(value: Optional[str] = None) -> bool:
461
465
  return True
462
466
 
463
467
 
464
- @dsl.component(base_image=_image.GCPC_IMAGE_TAG, install_kfp_package=False)
465
- def resolve_candidate_columns(
466
- candidate_columns: Optional[List[str]] = None,
467
- ) -> List[str]:
468
- """Returns candidate columns provided by the user or the default: ['candidate_0', 'candidate_1']."""
469
- return candidate_columns or ['candidate_0', 'candidate_1']
470
-
471
-
472
468
  @dsl.component(base_image=_image.GCPC_IMAGE_TAG, install_kfp_package=False)
473
469
  def resolve_upload_model(large_model_reference: str) -> bool:
474
470
  """Returns whether the model should be uploaded."""
@@ -510,93 +506,3 @@ def resolve_num_microbatches(large_model_reference: str) -> int:
510
506
  if 'llama' in large_model_reference.lower():
511
507
  return 2
512
508
  return 0
513
-
514
-
515
- @dsl.component(base_image=_image.GCPC_IMAGE_TAG, install_kfp_package=False)
516
- def read_file(path: str) -> str:
517
- """Reads the contents of the given file."""
518
- # pylint: disable=g-import-not-at-top,import-outside-toplevel,redefined-outer-name,reimported
519
- import re
520
- # pylint: enable=g-import-not-at-top,import-outside-toplevel,redefined-outer-name,reimported
521
-
522
- path = re.sub('^gs://', '/gcs/', path)
523
- with open(path, 'r') as f:
524
- return f.read()
525
-
526
-
527
- @dsl.component(base_image=_image.GCPC_IMAGE_TAG, install_kfp_package=False)
528
- def get_usage_metric(metadata: Dict[str, Any], key: str) -> bool: # pytype: disable=unsupported-operands
529
- """Extracts a single usage metric from metadata."""
530
- return metadata[key]
531
-
532
-
533
- @dsl.component(base_image=_image.GCPC_IMAGE_TAG, install_kfp_package=False)
534
- def dump_dict(value: Dict[Any, Any]) -> str:
535
- """Dumps the given dict to a JSON string."""
536
- # pylint: disable=g-import-not-at-top,import-outside-toplevel,redefined-outer-name,reimported
537
- import json
538
- # pylint: enable=g-import-not-at-top,import-outside-toplevel,redefined-outer-name,reimported
539
-
540
- return json.dumps(value).replace('"', '\\"')
541
-
542
-
543
- @dsl.component(base_image=_image.GCPC_IMAGE_TAG, install_kfp_package=False)
544
- def dump_list(value: List[Any]) -> str:
545
- """Dumps the given dict to a JSON string."""
546
- # pylint: disable=g-import-not-at-top,import-outside-toplevel,redefined-outer-name,reimported
547
- import json
548
- # pylint: enable=g-import-not-at-top,import-outside-toplevel,redefined-outer-name,reimported
549
-
550
- return json.dumps(value).replace('"', '\\"')
551
-
552
-
553
- @dsl.component(base_image=_image.GCPC_IMAGE_TAG, install_kfp_package=False)
554
- def identity(
555
- x: str,
556
- ) -> str:
557
- return x
558
-
559
-
560
- @dsl.component(base_image=_image.GCPC_IMAGE_TAG, install_kfp_package=False)
561
- def get_uri(artifact: dsl.Input[dsl.Artifact], is_dir: bool = False) -> str: # pytype: disable=unsupported-operands
562
- """Extracts the URI from an artifact."""
563
- # pylint: disable=g-import-not-at-top,import-outside-toplevel,redefined-outer-name,reimported
564
- import os
565
- # pylint: enable=g-import-not-at-top,import-outside-toplevel,redefined-outer-name,reimported
566
-
567
- if is_dir:
568
- return os.path.join(artifact.uri, '*')
569
- return artifact.uri
570
-
571
-
572
- @dsl.component(base_image=_image.GCPC_IMAGE_TAG, install_kfp_package=False)
573
- def get_empty_string() -> str:
574
- return ''
575
-
576
-
577
- @dsl.component(base_image=_image.GCPC_IMAGE_TAG, install_kfp_package=False)
578
- def validate_rlhf_inputs(
579
- large_model_reference: str,
580
- eval_dataset: Optional[str] = None,
581
- ) -> None:
582
- """Checks user-provided arguments are valid for the RLHF pipeline."""
583
- models_that_support_bulk_inference = {
584
- 't5-small',
585
- 't5-large',
586
- 't5-xl',
587
- 't5-xxl',
588
- 'llama-2-7b',
589
- 'llama-2-7b-chat',
590
- 'llama-2-13b',
591
- 'llama-2-13b-chat',
592
- }
593
- if (
594
- eval_dataset
595
- and large_model_reference not in models_that_support_bulk_inference
596
- ):
597
- raise ValueError(
598
- f'eval_dataset not supported for {large_model_reference}. '
599
- 'Please set this value to None when tuning this model. '
600
- 'This model can be evaluated after tuning using Batch or Online '
601
- 'Prediction.'
602
- )
@@ -17,4 +17,4 @@
17
17
  DO NOT EDIT - This file is generated, manual changes will be overridden.
18
18
  """
19
19
 
20
- IMAGE_TAG = '20240220_2307_RC00'
20
+ IMAGE_TAG = '20240327_1338'
@@ -33,22 +33,52 @@ def model_evaluation_text_generation_pairwise(
33
33
  judgments_dir: str,
34
34
  autosxs_metrics: dsl.Output[dsl.Metrics], # pylint: disable=unused-argument # pytype: disable=unsupported-operands
35
35
  gcp_resources: dsl.OutputPath(str), # pytype: disable=invalid-annotation
36
+ model_a_evaluation_path: dsl.OutputPath(str), # pylint: disable=unused-argument # pytype: disable=unsupported-operands
37
+ model_b_evaluation_path: dsl.OutputPath(str), # pylint: disable=unused-argument # pytype: disable=unsupported-operands
38
+ evaluation_count_path: dsl.OutputPath(int), # pylint: disable=unused-argument # pytype: disable=unsupported-operands
39
+ evaluation_dataset_path: dsl.OutputPath(str), # pylint: disable=unused-argument # pytype: disable=unsupported-operands
36
40
  human_preference_column: str = '',
41
+ project: str = _placeholders.PROJECT_ID_PLACEHOLDER,
42
+ location: str = _placeholders.LOCATION_PLACEHOLDER,
43
+ encryption_spec_key_name: str = '',
44
+ model_a: str = '',
45
+ model_b: str = '',
46
+ evaluation_dataset: str = '',
47
+ evaluation_dataset_metadata: str = '', # pylint: disable=unused-argument
48
+ task: str = '',
37
49
  ) -> dsl.ContainerSpec: # pylint: disable=g-doc-args
38
50
  """Compute AutoSXS metrics using judgments outputs from Arbiter.
39
51
 
40
52
  Args:
41
- judgments_dir: Path where store the Judgments.
53
+ judgments_dir: Path to store the Judgments.
42
54
  human_preference_column: The column containing ground truths. The default
43
55
  value is an empty string if not be provided by users.
56
+ project: Project to upload evaluation metrics to.
57
+ location: Location to upload evaluation metrics to.
58
+ encryption_spec_key_name: Customer-managed encryption key options. If this
59
+ is set, then all resources created by the component will be encrypted with
60
+ the provided encryption key.
61
+ model_a: Resource path for Model A.
62
+ model_b: Resource path for Model B.
63
+ evaluation_dataset: Path to the evaluation dataset.
64
+ evaluation_dataset_metadata: AutoSxS metrics metadata json string.
65
+ task: Task that was used for this AutoSxS run.
44
66
 
45
67
  Returns:
46
68
  autosxs_metrics: Autosxs win rate metrics and human alignment metrics.
47
69
  gcp_resources: Tracker for GCP resources created by this component.
70
+ model_a_evaluation_path: Path to write the ModelEvaluation for Model A if it
71
+ is a
72
+ ModelRegistry model.
73
+ model_b_evaluation: Path to write the ModelEvaluation for Model B if it is a
74
+ ModelRegistry model.
75
+ evaluation_count: Path to write the EvaluationCount number to.
76
+ evaluation_dataset_path: Path to write the path to the evaluation dataset.
77
+ This is needed because Pipeline outputs must be component outputs.
48
78
  """
49
79
  return gcpc_utils.build_serverless_customjob_container_spec(
50
- project=_placeholders.PROJECT_ID_PLACEHOLDER,
51
- location=_placeholders.LOCATION_PLACEHOLDER,
80
+ project=project,
81
+ location=location,
52
82
  custom_job_payload=utils.build_payload(
53
83
  display_name='model_evaluation_text_generation_pairwise',
54
84
  machine_type='n1-standard-4',
@@ -58,8 +88,20 @@ def model_evaluation_text_generation_pairwise(
58
88
  'autosxs_metrics',
59
89
  f'--judgments_dir={judgments_dir}',
60
90
  f'--human_preference_column={human_preference_column}',
91
+ f'--project={project}',
92
+ f'--location={location}',
61
93
  '--executor_input={{$.json_escape[1]}}',
94
+ f'--model_a={model_a}',
95
+ f'--model_b={model_b}',
96
+ f'--model_a_evaluation_path={model_a_evaluation_path}',
97
+ f'--model_b_evaluation_path={model_b_evaluation_path}',
98
+ f'--evaluation_count_path={evaluation_count_path}',
99
+ f'--evaluation_dataset_path={evaluation_dataset_path}',
100
+ f'--evaluation_dataset={evaluation_dataset}',
101
+ "--evaluation_dataset_metadata={{$.inputs.parameters['evaluation_dataset_metadata'].json_escape[0]}}",
102
+ f'--task={task}',
62
103
  ],
104
+ encryption_spec_key_name=encryption_spec_key_name,
63
105
  ),
64
106
  gcp_resources=gcp_resources,
65
107
  )
@@ -49,6 +49,9 @@ def online_evaluation_pairwise(
49
49
  judgments_format: str = 'jsonl',
50
50
  bigquery_destination_prefix: str = '',
51
51
  experimental_args: Dict[str, Any] = {},
52
+ project: str = _placeholders.PROJECT_ID_PLACEHOLDER,
53
+ location: str = _placeholders.LOCATION_PLACEHOLDER,
54
+ encryption_spec_key_name: str = '',
52
55
  ) -> dsl.ContainerSpec: # pylint: disable=g-doc-args
53
56
  """Evaluate two models using an autorater.
54
57
 
@@ -65,6 +68,11 @@ def online_evaluation_pairwise(
65
68
  bigquery_destination_prefix: BigQuery table to write judgments to if the
66
69
  specified format is 'bigquery'.
67
70
  experimental_args: Experimentally released arguments. Subject to change.
71
+ project: Project used to make autorater predictions.
72
+ location: Location used to make autorater predictions.
73
+ encryption_spec_key_name: Customer-managed encryption key options. If this
74
+ is set, then all resources created by the component will be encrypted with
75
+ the provided encryption key.
68
76
 
69
77
  Returns:
70
78
  judgments: Individual judgments used to calculate the win rates.
@@ -74,8 +82,8 @@ def online_evaluation_pairwise(
74
82
  metadata: Computed runtime metrics metadata from this component.
75
83
  """
76
84
  return gcpc_utils.build_serverless_customjob_container_spec(
77
- project=_placeholders.PROJECT_ID_PLACEHOLDER,
78
- location=_placeholders.LOCATION_PLACEHOLDER,
85
+ project=project,
86
+ location=location,
79
87
  custom_job_payload=utils.build_payload(
80
88
  display_name='online_evaluation_pairwise',
81
89
  machine_type='n1-standard-4',
@@ -86,6 +94,8 @@ def online_evaluation_pairwise(
86
94
  f'--inference_output_uri={inference_output_uri}',
87
95
  f'--human_preference_column={human_preference_column}',
88
96
  f'--task={task}',
97
+ f'--project={project}',
98
+ f'--location={location}',
89
99
  f'--prediction_endpoint_overrides={_get_prediction_endpoint_overrides()}',
90
100
  f'--output_dir={dsl.PIPELINE_ROOT_PLACEHOLDER}',
91
101
  f'--judgments_uri={judgments_uri}',
@@ -100,8 +110,10 @@ def online_evaluation_pairwise(
100
110
  "{{$.inputs.parameters['experimental_args'].json_escape[0]}}"
101
111
  ),
102
112
  '--executor_input={{$.json_escape[1]}}',
113
+ f'--kms_key_name={encryption_spec_key_name}',
103
114
  f'--metadata_path={metadata}',
104
115
  ],
116
+ encryption_spec_key_name=encryption_spec_key_name,
105
117
  ),
106
118
  gcp_resources=gcp_resources,
107
119
  )
@@ -28,11 +28,12 @@ def private_text_comparison_importer(
28
28
  choice_field_name: str,
29
29
  split: str,
30
30
  large_model_reference: str,
31
- image_uri: str,
32
31
  output_dataset_path: kfp.dsl.OutputPath(str), # pytype: disable=invalid-annotation
33
32
  gcp_resources: kfp.dsl.OutputPath(str), # pytype: disable=invalid-annotation
33
+ image_uri: str = utils.get_default_image_uri('refined_cpu', ''),
34
34
  machine_type: str = 'e2-highmem-8',
35
35
  instruction: str = '',
36
+ encryption_spec_key_name: str = '',
36
37
  ) -> kfp.dsl.ContainerSpec: # pylint: disable=g-doc-args
37
38
  """Import a text dataset.
38
39
 
@@ -52,8 +53,12 @@ def private_text_comparison_importer(
52
53
  this component tokenizes and then caches the tokenized tasks.
53
54
  machine_type: The type of the machine to provision for the custom job.
54
55
  instruction: Optional instruction to prepend to inputs field.
55
- image_uri: Location of the text comparison importer image.
56
+ image_uri: Optional location of the text comparison importer image.
56
57
  dataflow_worker_image_uri: Location of the Dataflow worker image.
58
+ encryption_spec_key_name: Customer-managed encryption key. If this is set,
59
+ then all resources created by the CustomJob will be encrypted with the
60
+ provided encryption key. Note that this is not supported for TPU at the
61
+ moment.
57
62
 
58
63
  Returns:
59
64
  output_dataset_path: Path to cached SeqIO task created from input dataset.
@@ -67,6 +72,7 @@ def private_text_comparison_importer(
67
72
  machine_type=machine_type,
68
73
  image_uri=image_uri,
69
74
  args=[
75
+ '--app_name=text_comparison_importer',
70
76
  f'--input_text={input_text}',
71
77
  f'--inputs_field_name={inputs_field_name}',
72
78
  f'--comma_separated_candidates_field_names={comma_separated_candidates_field_names}',
@@ -81,6 +87,7 @@ def private_text_comparison_importer(
81
87
  f'{kfp.dsl.PIPELINE_TASK_ID_PLACEHOLDER}'
82
88
  ),
83
89
  ],
90
+ encryption_spec_key_name=encryption_spec_key_name,
84
91
  ),
85
92
  gcp_resources=gcp_resources,
86
93
  )