oracle-ads 2.11.9__py3-none-any.whl → 2.11.11__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 (88) hide show
  1. ads/aqua/__init__.py +1 -1
  2. ads/aqua/{base.py → app.py} +27 -7
  3. ads/aqua/cli.py +59 -17
  4. ads/aqua/common/__init__.py +5 -0
  5. ads/aqua/{decorator.py → common/decorator.py} +14 -8
  6. ads/aqua/common/enums.py +69 -0
  7. ads/aqua/{exception.py → common/errors.py} +28 -0
  8. ads/aqua/{utils.py → common/utils.py} +193 -95
  9. ads/aqua/config/config.py +18 -0
  10. ads/aqua/constants.py +51 -33
  11. ads/aqua/data.py +15 -26
  12. ads/aqua/evaluation/__init__.py +8 -0
  13. ads/aqua/evaluation/constants.py +53 -0
  14. ads/aqua/evaluation/entities.py +170 -0
  15. ads/aqua/evaluation/errors.py +71 -0
  16. ads/aqua/{evaluation.py → evaluation/evaluation.py} +122 -370
  17. ads/aqua/extension/__init__.py +2 -0
  18. ads/aqua/extension/aqua_ws_msg_handler.py +97 -0
  19. ads/aqua/extension/base_handler.py +0 -7
  20. ads/aqua/extension/common_handler.py +12 -6
  21. ads/aqua/extension/deployment_handler.py +70 -4
  22. ads/aqua/extension/errors.py +10 -0
  23. ads/aqua/extension/evaluation_handler.py +5 -3
  24. ads/aqua/extension/evaluation_ws_msg_handler.py +43 -0
  25. ads/aqua/extension/finetune_handler.py +41 -3
  26. ads/aqua/extension/model_handler.py +56 -4
  27. ads/aqua/extension/models/__init__.py +0 -0
  28. ads/aqua/extension/models/ws_models.py +69 -0
  29. ads/aqua/extension/ui_handler.py +65 -4
  30. ads/aqua/extension/ui_websocket_handler.py +124 -0
  31. ads/aqua/extension/utils.py +1 -1
  32. ads/aqua/finetuning/__init__.py +7 -0
  33. ads/aqua/finetuning/constants.py +17 -0
  34. ads/aqua/finetuning/entities.py +102 -0
  35. ads/aqua/{finetune.py → finetuning/finetuning.py} +170 -141
  36. ads/aqua/model/__init__.py +8 -0
  37. ads/aqua/model/constants.py +46 -0
  38. ads/aqua/model/entities.py +266 -0
  39. ads/aqua/model/enums.py +26 -0
  40. ads/aqua/{model.py → model/model.py} +405 -309
  41. ads/aqua/modeldeployment/__init__.py +8 -0
  42. ads/aqua/modeldeployment/constants.py +26 -0
  43. ads/aqua/{deployment.py → modeldeployment/deployment.py} +288 -227
  44. ads/aqua/modeldeployment/entities.py +142 -0
  45. ads/aqua/modeldeployment/inference.py +75 -0
  46. ads/aqua/ui.py +88 -8
  47. ads/cli.py +55 -7
  48. ads/common/decorator/threaded.py +97 -0
  49. ads/common/serializer.py +2 -2
  50. ads/config.py +5 -1
  51. ads/jobs/builders/infrastructure/dsc_job.py +49 -6
  52. ads/model/datascience_model.py +1 -1
  53. ads/model/deployment/model_deployment.py +11 -0
  54. ads/model/model_metadata.py +17 -6
  55. ads/opctl/operator/lowcode/anomaly/README.md +0 -2
  56. ads/opctl/operator/lowcode/anomaly/__main__.py +3 -3
  57. ads/opctl/operator/lowcode/anomaly/environment.yaml +0 -2
  58. ads/opctl/operator/lowcode/anomaly/model/automlx.py +2 -2
  59. ads/opctl/operator/lowcode/anomaly/model/autots.py +1 -1
  60. ads/opctl/operator/lowcode/anomaly/model/base_model.py +13 -17
  61. ads/opctl/operator/lowcode/anomaly/operator_config.py +2 -0
  62. ads/opctl/operator/lowcode/anomaly/schema.yaml +1 -2
  63. ads/opctl/operator/lowcode/anomaly/utils.py +3 -2
  64. ads/opctl/operator/lowcode/common/transformations.py +2 -1
  65. ads/opctl/operator/lowcode/common/utils.py +1 -1
  66. ads/opctl/operator/lowcode/forecast/README.md +1 -3
  67. ads/opctl/operator/lowcode/forecast/__main__.py +3 -18
  68. ads/opctl/operator/lowcode/forecast/const.py +2 -0
  69. ads/opctl/operator/lowcode/forecast/environment.yaml +1 -2
  70. ads/opctl/operator/lowcode/forecast/model/arima.py +1 -0
  71. ads/opctl/operator/lowcode/forecast/model/automlx.py +7 -4
  72. ads/opctl/operator/lowcode/forecast/model/autots.py +1 -0
  73. ads/opctl/operator/lowcode/forecast/model/base_model.py +38 -22
  74. ads/opctl/operator/lowcode/forecast/model/factory.py +33 -4
  75. ads/opctl/operator/lowcode/forecast/model/forecast_datasets.py +15 -1
  76. ads/opctl/operator/lowcode/forecast/model/ml_forecast.py +234 -0
  77. ads/opctl/operator/lowcode/forecast/model/neuralprophet.py +9 -1
  78. ads/opctl/operator/lowcode/forecast/model/prophet.py +1 -0
  79. ads/opctl/operator/lowcode/forecast/model_evaluator.py +147 -0
  80. ads/opctl/operator/lowcode/forecast/operator_config.py +2 -1
  81. ads/opctl/operator/lowcode/forecast/schema.yaml +7 -2
  82. ads/opctl/operator/lowcode/forecast/utils.py +18 -44
  83. {oracle_ads-2.11.9.dist-info → oracle_ads-2.11.11.dist-info}/METADATA +9 -12
  84. {oracle_ads-2.11.9.dist-info → oracle_ads-2.11.11.dist-info}/RECORD +87 -61
  85. ads/aqua/job.py +0 -29
  86. {oracle_ads-2.11.9.dist-info → oracle_ads-2.11.11.dist-info}/LICENSE.txt +0 -0
  87. {oracle_ads-2.11.9.dist-info → oracle_ads-2.11.11.dist-info}/WHEEL +0 -0
  88. {oracle_ads-2.11.9.dist-info → oracle_ads-2.11.11.dist-info}/entry_points.txt +0 -0
@@ -5,9 +5,8 @@
5
5
 
6
6
  import json
7
7
  import os
8
- from dataclasses import asdict, dataclass, field
9
- from enum import Enum
10
- from typing import Dict, Optional
8
+ from dataclasses import asdict, fields, MISSING
9
+ from typing import Dict
11
10
 
12
11
  from oci.data_science.models import (
13
12
  Metadata,
@@ -16,11 +15,14 @@ from oci.data_science.models import (
16
15
  )
17
16
 
18
17
  from ads.aqua import ODSC_MODEL_COMPARTMENT_OCID, logger
19
- from ads.aqua.base import AquaApp
20
- from ads.aqua.data import AquaResourceIdentifier, Resource, Tags
21
- from ads.aqua.exception import AquaFileExistsError, AquaValueError
22
- from ads.aqua.job import AquaJobSummary
23
- from ads.aqua.utils import (
18
+ from ads.aqua.app import AquaApp
19
+ from ads.aqua.common.enums import Resource, Tags
20
+ from ads.aqua.common.errors import AquaFileExistsError, AquaValueError
21
+ from ads.aqua.common.utils import (
22
+ get_container_image,
23
+ upload_local_to_os,
24
+ )
25
+ from ads.aqua.constants import (
24
26
  DEFAULT_FT_BATCH_SIZE,
25
27
  DEFAULT_FT_BLOCK_STORAGE_SIZE,
26
28
  DEFAULT_FT_REPLICA,
@@ -28,14 +30,16 @@ from ads.aqua.utils import (
28
30
  JOB_INFRASTRUCTURE_TYPE_DEFAULT_NETWORKING,
29
31
  UNKNOWN,
30
32
  UNKNOWN_DICT,
31
- get_container_image,
32
- upload_local_to_os,
33
33
  )
34
+ from ads.aqua.config.config import get_finetuning_config_defaults
35
+ from ads.aqua.data import AquaResourceIdentifier
36
+ from ads.aqua.finetuning.constants import *
37
+ from ads.aqua.finetuning.entities import *
34
38
  from ads.common.auth import default_signer
35
39
  from ads.common.object_storage_details import ObjectStorageDetails
36
- from ads.common.serializer import DataClassSerializable
37
40
  from ads.common.utils import get_console_link
38
41
  from ads.config import (
42
+ AQUA_FINETUNING_CONTAINER_OVERRIDE_FLAG_METADATA_NAME,
39
43
  AQUA_JOB_SUBNET_ID,
40
44
  AQUA_MODEL_FINETUNING_CONFIG,
41
45
  COMPARTMENT_OCID,
@@ -54,100 +58,6 @@ from ads.model.model_metadata import (
54
58
  from ads.telemetry import telemetry
55
59
 
56
60
 
57
- class FineTuneCustomMetadata(Enum):
58
- FINE_TUNE_SOURCE = "fine_tune_source"
59
- FINE_TUNE_SOURCE_NAME = "fine_tune_source_name"
60
- FINE_TUNE_OUTPUT_PATH = "fine_tune_output_path"
61
- FINE_TUNE_JOB_ID = "fine_tune_job_id"
62
- FINE_TUNE_JOB_RUN_ID = "fine_tune_job_run_id"
63
- SERVICE_MODEL_ARTIFACT_LOCATION = "artifact_location"
64
- SERVICE_MODEL_DEPLOYMENT_CONTAINER = "deployment-container"
65
- SERVICE_MODEL_FINE_TUNE_CONTAINER = "finetune-container"
66
-
67
-
68
- @dataclass(repr=False)
69
- class AquaFineTuningParams(DataClassSerializable):
70
- epochs: int = None
71
- learning_rate: float = None
72
- sample_packing: str = "True"
73
-
74
-
75
- @dataclass(repr=False)
76
- class AquaFineTuningSummary(AquaJobSummary, DataClassSerializable):
77
- parameters: AquaFineTuningParams = field(default_factory=AquaFineTuningParams)
78
-
79
-
80
- @dataclass(repr=False)
81
- class CreateFineTuningDetails(DataClassSerializable):
82
- """Dataclass to create aqua model fine tuning.
83
-
84
- Fields
85
- ------
86
- ft_source_id: str
87
- The fine tuning source id. Must be model ocid.
88
- ft_name: str
89
- The name for fine tuning.
90
- dataset_path: str
91
- The dataset path for fine tuning. Could be either a local path from notebook session
92
- or an object storage path.
93
- report_path: str
94
- The report path for fine tuning. Must be an object storage path.
95
- ft_parameters: dict
96
- The parameters for fine tuning.
97
- shape_name: str
98
- The shape name for fine tuning job infrastructure.
99
- replica: int
100
- The replica for fine tuning job runtime.
101
- validation_set_size: float
102
- The validation set size for fine tuning job. Must be a float in between [0,1).
103
- ft_description: (str, optional). Defaults to `None`.
104
- The description for fine tuning.
105
- compartment_id: (str, optional). Defaults to `None`.
106
- The compartment id for fine tuning.
107
- project_id: (str, optional). Defaults to `None`.
108
- The project id for fine tuning.
109
- experiment_id: (str, optional). Defaults to `None`.
110
- The fine tuning model version set id. If provided,
111
- fine tuning model will be associated with it.
112
- experiment_name: (str, optional). Defaults to `None`.
113
- The fine tuning model version set name. If provided,
114
- the fine tuning version set with the same name will be used if exists,
115
- otherwise a new model version set will be created with the name.
116
- experiment_description: (str, optional). Defaults to `None`.
117
- The description for fine tuning model version set.
118
- block_storage_size: (int, optional). Defaults to 256.
119
- The storage for fine tuning job infrastructure.
120
- subnet_id: (str, optional). Defaults to `None`.
121
- The custom egress for fine tuning job.
122
- log_group_id: (str, optional). Defaults to `None`.
123
- The log group id for fine tuning job infrastructure.
124
- log_id: (str, optional). Defaults to `None`.
125
- The log id for fine tuning job infrastructure.
126
- force_overwrite: (bool, optional). Defaults to `False`.
127
- Whether to force overwrite the existing file in object storage.
128
- """
129
-
130
- ft_source_id: str
131
- ft_name: str
132
- dataset_path: str
133
- report_path: str
134
- ft_parameters: dict
135
- shape_name: str
136
- replica: int
137
- validation_set_size: float
138
- ft_description: Optional[str] = None
139
- compartment_id: Optional[str] = None
140
- project_id: Optional[str] = None
141
- experiment_id: Optional[str] = None
142
- experiment_name: Optional[str] = None
143
- experiment_description: Optional[str] = None
144
- block_storage_size: Optional[int] = None
145
- subnet_id: Optional[str] = None
146
- log_id: Optional[str] = None
147
- log_group_id: Optional[str] = None
148
- force_overwrite: Optional[bool] = False
149
-
150
-
151
61
  class AquaFineTuningApp(AquaApp):
152
62
  """Provides a suite of APIs to interact with Aqua fine-tuned models within the Oracle
153
63
  Cloud Infrastructure Data Science service, serving as an interface for creating fine-tuned models.
@@ -190,17 +100,22 @@ class AquaFineTuningApp(AquaApp):
190
100
  try:
191
101
  create_fine_tuning_details = CreateFineTuningDetails(**kwargs)
192
102
  except:
103
+ allowed_create_fine_tuning_details = ", ".join(
104
+ field.name for field in fields(CreateFineTuningDetails)
105
+ ).rstrip()
193
106
  raise AquaValueError(
194
107
  "Invalid create fine tuning parameters. Allowable parameters are: "
195
- f"{', '.join(list(asdict(CreateFineTuningDetails).keys()))}."
108
+ f"{allowed_create_fine_tuning_details}."
196
109
  )
197
110
 
198
111
  source = self.get_source(create_fine_tuning_details.ft_source_id)
199
- if source.compartment_id != ODSC_MODEL_COMPARTMENT_OCID:
200
- raise AquaValueError(
201
- f"Fine tuning is only supported for Aqua service models in {ODSC_MODEL_COMPARTMENT_OCID}. "
202
- "Use a valid Aqua service model id instead."
203
- )
112
+
113
+ # todo: revisit validation for fine tuned models
114
+ # if source.compartment_id != ODSC_MODEL_COMPARTMENT_OCID:
115
+ # raise AquaValueError(
116
+ # f"Fine tuning is only supported for Aqua service models in {ODSC_MODEL_COMPARTMENT_OCID}. "
117
+ # "Use a valid Aqua service model id instead."
118
+ # )
204
119
 
205
120
  target_compartment = (
206
121
  create_fine_tuning_details.compartment_id or COMPARTMENT_OCID
@@ -247,9 +162,12 @@ class AquaFineTuningApp(AquaApp):
247
162
  **create_fine_tuning_details.ft_parameters,
248
163
  )
249
164
  except:
165
+ allowed_fine_tuning_parameters = ", ".join(
166
+ field.name for field in fields(AquaFineTuningParams)
167
+ ).rstrip()
250
168
  raise AquaValueError(
251
169
  "Invalid fine tuning parameters. Fine tuning parameters should "
252
- f"be a dictionary with keys: {', '.join(list(asdict(AquaFineTuningParams).keys()))}."
170
+ f"be a dictionary with keys: {allowed_fine_tuning_parameters}."
253
171
  )
254
172
 
255
173
  experiment_model_version_set_id = create_fine_tuning_details.experiment_id
@@ -307,19 +225,20 @@ class AquaFineTuningApp(AquaApp):
307
225
 
308
226
  ft_model_custom_metadata = ModelCustomMetadata()
309
227
  ft_model_custom_metadata.add(
310
- key=FineTuneCustomMetadata.FINE_TUNE_SOURCE.value,
228
+ key=FineTuneCustomMetadata.FINE_TUNE_SOURCE,
311
229
  value=create_fine_tuning_details.ft_source_id,
312
230
  )
313
231
  ft_model_custom_metadata.add(
314
- key=FineTuneCustomMetadata.FINE_TUNE_SOURCE_NAME.value,
232
+ key=FineTuneCustomMetadata.FINE_TUNE_SOURCE_NAME,
315
233
  value=source.display_name,
316
234
  )
317
235
  service_model_artifact_location = source.custom_metadata_list.get(
318
- FineTuneCustomMetadata.SERVICE_MODEL_ARTIFACT_LOCATION.value
236
+ FineTuneCustomMetadata.SERVICE_MODEL_ARTIFACT_LOCATION
319
237
  )
320
238
  service_model_deployment_container = source.custom_metadata_list.get(
321
- FineTuneCustomMetadata.SERVICE_MODEL_DEPLOYMENT_CONTAINER.value
239
+ FineTuneCustomMetadata.SERVICE_MODEL_DEPLOYMENT_CONTAINER
322
240
  )
241
+
323
242
  ft_model_custom_metadata.add(
324
243
  key=service_model_artifact_location.key,
325
244
  value=service_model_artifact_location.value,
@@ -350,8 +269,8 @@ class AquaFineTuningApp(AquaApp):
350
269
  )
351
270
 
352
271
  ft_job_freeform_tags = {
353
- Tags.AQUA_TAG.value: UNKNOWN,
354
- Tags.AQUA_FINE_TUNED_MODEL_TAG.value: f"{source.id}#{source.display_name}",
272
+ Tags.AQUA_TAG: UNKNOWN,
273
+ Tags.AQUA_FINE_TUNED_MODEL_TAG: f"{source.id}#{source.display_name}",
355
274
  }
356
275
 
357
276
  ft_job = Job(name=ft_model.display_name).with_infrastructure(
@@ -381,10 +300,19 @@ class AquaFineTuningApp(AquaApp):
381
300
  ft_config = self.get_finetuning_config(source.id)
382
301
 
383
302
  ft_container = source.custom_metadata_list.get(
384
- FineTuneCustomMetadata.SERVICE_MODEL_FINE_TUNE_CONTAINER.value
303
+ FineTuneCustomMetadata.SERVICE_MODEL_FINE_TUNE_CONTAINER
385
304
  ).value
386
-
387
- batch_size = (
305
+ is_custom_container = False
306
+ try:
307
+ # Check if the container override flag is set. If set, then the user has chosen custom image
308
+ if source.custom_metadata_list.get(
309
+ AQUA_FINETUNING_CONTAINER_OVERRIDE_FLAG_METADATA_NAME
310
+ ).value:
311
+ is_custom_container = True
312
+ except Exception:
313
+ pass
314
+
315
+ ft_parameters.batch_size = ft_parameters.batch_size or (
388
316
  ft_config.get("shape", UNKNOWN_DICT)
389
317
  .get(create_fine_tuning_details.shape_name, UNKNOWN_DICT)
390
318
  .get("batch_size", DEFAULT_FT_BATCH_SIZE)
@@ -398,7 +326,6 @@ class AquaFineTuningApp(AquaApp):
398
326
  dataset_path=ft_dataset_path,
399
327
  report_path=create_fine_tuning_details.report_path,
400
328
  replica=create_fine_tuning_details.replica,
401
- batch_size=batch_size,
402
329
  finetuning_params=finetuning_params,
403
330
  val_set_size=(
404
331
  create_fine_tuning_details.validation_set_size
@@ -406,6 +333,7 @@ class AquaFineTuningApp(AquaApp):
406
333
  ),
407
334
  parameters=ft_parameters,
408
335
  ft_container=ft_container,
336
+ is_custom_container=is_custom_container,
409
337
  )
410
338
  ).create()
411
339
  logger.debug(
@@ -422,11 +350,11 @@ class AquaFineTuningApp(AquaApp):
422
350
  )
423
351
 
424
352
  ft_model_custom_metadata.add(
425
- key=FineTuneCustomMetadata.FINE_TUNE_JOB_ID.value,
353
+ key=FineTuneCustomMetadata.FINE_TUNE_JOB_ID,
426
354
  value=ft_job.id,
427
355
  )
428
356
  ft_model_custom_metadata.add(
429
- key=FineTuneCustomMetadata.FINE_TUNE_JOB_RUN_ID.value,
357
+ key=FineTuneCustomMetadata.FINE_TUNE_JOB_RUN_ID,
430
358
  value=ft_job_run.id,
431
359
  )
432
360
  updated_custom_metadata_list = [
@@ -435,16 +363,17 @@ class AquaFineTuningApp(AquaApp):
435
363
  ]
436
364
 
437
365
  source_freeform_tags = source.freeform_tags or {}
438
- source_freeform_tags.pop(Tags.LICENSE.value, None)
439
- source_freeform_tags.update({Tags.READY_TO_FINE_TUNE.value: "false"})
440
- source_freeform_tags.update({Tags.AQUA_TAG.value: UNKNOWN})
366
+ source_freeform_tags.pop(Tags.LICENSE, None)
367
+ source_freeform_tags.update({Tags.READY_TO_FINE_TUNE: "false"})
368
+ source_freeform_tags.update({Tags.AQUA_TAG: UNKNOWN})
369
+ source_freeform_tags.pop(Tags.BASE_MODEL_CUSTOM, None)
441
370
 
442
371
  self.update_model(
443
372
  model_id=ft_model.id,
444
373
  update_model_details=UpdateModelDetails(
445
374
  custom_metadata_list=updated_custom_metadata_list,
446
375
  freeform_tags={
447
- Tags.AQUA_FINE_TUNED_MODEL_TAG.value: (
376
+ Tags.AQUA_FINE_TUNED_MODEL_TAG: (
448
377
  f"{source.id}#{source.display_name}"
449
378
  ),
450
379
  **source_freeform_tags,
@@ -489,7 +418,7 @@ class AquaFineTuningApp(AquaApp):
489
418
  id=ft_model.id,
490
419
  name=ft_model.display_name,
491
420
  console_url=get_console_link(
492
- resource=Resource.MODEL.value,
421
+ resource=Resource.MODEL,
493
422
  ocid=ft_model.id,
494
423
  region=self.region,
495
424
  ),
@@ -500,7 +429,7 @@ class AquaFineTuningApp(AquaApp):
500
429
  id=experiment_model_version_set_id,
501
430
  name=experiment_model_version_set_name,
502
431
  url=get_console_link(
503
- resource=Resource.MODEL_VERSION_SET.value,
432
+ resource=Resource.MODEL_VERSION_SET,
504
433
  ocid=experiment_model_version_set_id,
505
434
  region=self.region,
506
435
  ),
@@ -509,7 +438,7 @@ class AquaFineTuningApp(AquaApp):
509
438
  id=source.id,
510
439
  name=source.display_name,
511
440
  url=get_console_link(
512
- resource=Resource.MODEL.value,
441
+ resource=Resource.MODEL,
513
442
  ocid=source.id,
514
443
  region=self.region,
515
444
  ),
@@ -518,18 +447,22 @@ class AquaFineTuningApp(AquaApp):
518
447
  id=ft_job.id,
519
448
  name=ft_job.name,
520
449
  url=get_console_link(
521
- resource=Resource.JOB.value,
450
+ resource=Resource.JOB,
522
451
  ocid=ft_job.id,
523
452
  region=self.region,
524
453
  ),
525
454
  ),
526
455
  tags=dict(
527
- aqua_finetuning=Tags.AQUA_FINE_TUNING.value,
456
+ aqua_finetuning=Tags.AQUA_FINE_TUNING,
528
457
  finetuning_job_id=ft_job.id,
529
458
  finetuning_source=source.id,
530
459
  finetuning_experiment_id=experiment_model_version_set_id,
531
460
  ),
532
- parameters=ft_parameters,
461
+ parameters={
462
+ key: value
463
+ for key, value in asdict(ft_parameters).items()
464
+ if value is not None
465
+ },
533
466
  )
534
467
 
535
468
  def _build_fine_tuning_runtime(
@@ -539,15 +472,19 @@ class AquaFineTuningApp(AquaApp):
539
472
  dataset_path: str,
540
473
  report_path: str,
541
474
  replica: int,
542
- batch_size: int,
543
475
  val_set_size: float,
544
476
  parameters: AquaFineTuningParams,
545
477
  ft_container: str = None,
546
478
  finetuning_params: str = None,
479
+ is_custom_container: bool = False,
547
480
  ) -> Runtime:
548
481
  """Builds fine tuning runtime for Job."""
549
- container = get_container_image(
550
- container_type=ft_container,
482
+ container = (
483
+ get_container_image(
484
+ container_type=ft_container,
485
+ )
486
+ if not is_custom_container
487
+ else ft_container
551
488
  )
552
489
  runtime = (
553
490
  ContainerRuntime()
@@ -562,9 +499,12 @@ class AquaFineTuningApp(AquaApp):
562
499
  },
563
500
  }
564
501
  ),
565
- "OCI__LAUNCH_CMD": (
566
- f"--micro_batch_size {batch_size} --num_epochs {parameters.epochs} --learning_rate {parameters.learning_rate} --training_data {dataset_path} --output_dir {report_path} --val_set_size {val_set_size} --sample_packing {parameters.sample_packing} "
567
- + (f"{finetuning_params}" if finetuning_params else "")
502
+ "OCI__LAUNCH_CMD": self._build_oci_launch_cmd(
503
+ dataset_path=dataset_path,
504
+ report_path=report_path,
505
+ val_set_size=val_set_size,
506
+ parameters=parameters,
507
+ finetuning_params=finetuning_params,
568
508
  ),
569
509
  "CONDA_BUCKET_NS": CONDA_BUCKET_NS,
570
510
  }
@@ -575,6 +515,30 @@ class AquaFineTuningApp(AquaApp):
575
515
 
576
516
  return runtime
577
517
 
518
+ @staticmethod
519
+ def _build_oci_launch_cmd(
520
+ dataset_path: str,
521
+ report_path: str,
522
+ val_set_size: float,
523
+ parameters: AquaFineTuningParams,
524
+ finetuning_params: str = None,
525
+ ) -> str:
526
+ """Builds the oci launch cmd for fine tuning container runtime."""
527
+ oci_launch_cmd = f"--training_data {dataset_path} --output_dir {report_path} --val_set_size {val_set_size} "
528
+ for key, value in asdict(parameters).items():
529
+ if value is not None:
530
+ if key == "batch_size":
531
+ oci_launch_cmd += f"--micro_{key} {value} "
532
+ elif key == "epochs":
533
+ oci_launch_cmd += f"--num_{key} {value} "
534
+ elif key == "lora_target_modules":
535
+ oci_launch_cmd += f"--{key} {','.join(str(k) for k in value)} "
536
+ else:
537
+ oci_launch_cmd += f"--{key} {value} "
538
+
539
+ oci_launch_cmd += f"{finetuning_params}" if finetuning_params else ""
540
+ return oci_launch_cmd.rstrip()
541
+
578
542
  @telemetry(
579
543
  entry_point="plugin=finetuning&action=get_finetuning_config", name="aqua"
580
544
  )
@@ -592,4 +556,69 @@ class AquaFineTuningApp(AquaApp):
592
556
  A dict of allowed finetuning configs.
593
557
  """
594
558
 
595
- return self.get_config(model_id, AQUA_MODEL_FINETUNING_CONFIG)
559
+ config = self.get_config(model_id, AQUA_MODEL_FINETUNING_CONFIG)
560
+ if not config:
561
+ logger.info(f"Fetching default fine-tuning config for model: {model_id}")
562
+ config = get_finetuning_config_defaults()
563
+ return config
564
+
565
+ @telemetry(
566
+ entry_point="plugin=finetuning&action=get_finetuning_default_params",
567
+ name="aqua",
568
+ )
569
+ def get_finetuning_default_params(self, model_id: str) -> Dict:
570
+ """Gets the default params set in the finetuning configs for the given model. Only the fields that are
571
+ available in AquaFineTuningParams will be accessible for user overrides.
572
+
573
+ Parameters
574
+ ----------
575
+ model_id: str
576
+ The OCID of the Aqua model.
577
+
578
+ Returns
579
+ -------
580
+ Dict:
581
+ Dict of parameters from the loaded from finetuning config json file. If config information is not available,
582
+ then an empty dict is returned.
583
+ """
584
+ default_params = {"params": {}}
585
+ finetuning_config = self.get_finetuning_config(model_id)
586
+ config_parameters = finetuning_config.get("configuration", UNKNOWN_DICT)
587
+ dataclass_fields = {field.name for field in fields(AquaFineTuningParams)}
588
+ for name, value in config_parameters.items():
589
+ if name == "micro_batch_size":
590
+ name = "batch_size"
591
+ if name in dataclass_fields:
592
+ default_params["params"][name] = value
593
+
594
+ return default_params
595
+
596
+ def validate_finetuning_params(self, params: Dict = None) -> Dict:
597
+ """Validate if the fine-tuning parameters passed by the user can be overridden. Parameter values are not
598
+ validated, only param keys are validated.
599
+
600
+ Parameters
601
+ ----------
602
+ params :Dict, optional
603
+ Params passed by the user.
604
+
605
+ Returns
606
+ -------
607
+ Return a list of restricted params.
608
+ """
609
+ try:
610
+ AquaFineTuningParams(
611
+ **params,
612
+ )
613
+ except Exception as e:
614
+ logger.debug(str(e))
615
+ allowed_fine_tuning_parameters = ", ".join(
616
+ f"{field.name} (required)" if field.default is MISSING else field.name
617
+ for field in fields(AquaFineTuningParams)
618
+ ).rstrip()
619
+ raise AquaValueError(
620
+ f"Invalid fine tuning parameters. Allowable parameters are: "
621
+ f"{allowed_fine_tuning_parameters}."
622
+ )
623
+
624
+ return dict(valid=True)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*--
3
+
4
+ # Copyright (c) 2024 Oracle and/or its affiliates.
5
+ # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6
+ from ads.aqua.model.model import AquaModelApp
7
+
8
+ __all__ = ["AquaModelApp"]
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright (c) 2024 Oracle and/or its affiliates.
4
+ # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5
+
6
+ """
7
+ aqua.model.constants
8
+ ~~~~~~~~~~~~~~~~~~~~
9
+
10
+ This module contains constants/enums used in Aqua Model.
11
+ """
12
+ from ads.common.extended_enum import ExtendedEnumMeta
13
+
14
+
15
+ class ModelCustomMetadataFields(str, metaclass=ExtendedEnumMeta):
16
+ ARTIFACT_LOCATION = "artifact_location"
17
+ DEPLOYMENT_CONTAINER = "deployment-container"
18
+ EVALUATION_CONTAINER = "evaluation-container"
19
+ FINETUNE_CONTAINER = "finetune-container"
20
+
21
+
22
+ class ModelTask(str, metaclass=ExtendedEnumMeta):
23
+ TEXT_GENERATION = "text-generation"
24
+
25
+
26
+ class FineTuningMetricCategories(str, metaclass=ExtendedEnumMeta):
27
+ VALIDATION = "validation"
28
+ TRAINING = "training"
29
+
30
+
31
+ class ModelType(str, metaclass=ExtendedEnumMeta):
32
+ FT = "FT" # Fine Tuned Model
33
+ BASE = "BASE" # Base model
34
+
35
+
36
+ # TODO: merge metadata key used in create FT
37
+ class FineTuningCustomMetadata(str, metaclass=ExtendedEnumMeta):
38
+ FT_SOURCE = "fine_tune_source"
39
+ FT_SOURCE_NAME = "fine_tune_source_name"
40
+ FT_OUTPUT_PATH = "fine_tune_output_path"
41
+ FT_JOB_ID = "fine_tune_job_id"
42
+ FT_JOB_RUN_ID = "fine_tune_jobrun_id"
43
+ TRAINING_METRICS_FINAL = "train_metrics_final"
44
+ VALIDATION_METRICS_FINAL = "val_metrics_final"
45
+ TRAINING_METRICS_EPOCH = "train_metrics_epoch"
46
+ VALIDATION_METRICS_EPOCH = "val_metrics_epoch"