GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: expose env var in cust training class run func args · googleapis/python-aiplatform@05ca77d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • google/cloud/aiplatform
    • training_jobs.py
  • tests/unit/aiplatform
    • test_training_jobs.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎google/cloud/aiplatform/training_jobs.py‎

Copy file name to clipboardExpand all lines: google/cloud/aiplatform/training_jobs.py
+132Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,7 @@ def run(
18051805
service_account: Optional[str] = None,
18061806
bigquery_destination: Optional[str] = None,
18071807
args: Optional[List[Union[str, float, int]]] = None,
1808+
environment_variables: Optional[Dict[str, str]] = None,
18081809
replica_count: int = 0,
18091810
machine_type: str = "n1-standard-4",
18101811
accelerator_type: str = "ACCELERATOR_TYPE_UNSPECIFIED",
@@ -1880,6 +1881,13 @@ def run(
18801881
base_output_dir (str):
18811882
GCS output directory of job. If not provided a
18821883
timestamped directory in the staging directory will be used.
1884+
1885+
AI Platform sets the following environment variables when it runs your training code:
1886+
1887+
- AIP_MODEL_DIR: a Cloud Storage URI of a directory intended for saving model artifacts, i.e. <base_output_dir>/model/
1888+
- AIP_CHECKPOINT_DIR: a Cloud Storage URI of a directory intended for saving checkpoints, i.e. <base_output_dir>/checkpoints/
1889+
- AIP_TENSORBOARD_LOG_DIR: a Cloud Storage URI of a directory intended for saving TensorBoard logs, i.e. <base_output_dir>/logs/
1890+
18831891
service_account (str):
18841892
Specifies the service account for workload run-as account.
18851893
Users submitting jobs must have act-as permission on this run-as account.
@@ -1900,6 +1908,16 @@ def run(
19001908
- AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test"
19011909
args (List[Unions[str, int, float]]):
19021910
Command line arguments to be passed to the Python script.
1911+
environment_variables (Dict[str, str]):
1912+
Environment variables to be passed to the container.
1913+
Should be a dictionary where keys are environment variable names
1914+
and values are environment variable values for those names.
1915+
At most 10 environment variables can be specified.
1916+
The Name of the environment variable must be unique.
1917+
1918+
environment_variables = {
1919+
'MY_KEY': 'MY_VALUE'
1920+
}
19031921
replica_count (int):
19041922
The number of worker replicas. If replica count = 1 then one chief
19051923
replica will be provisioned. If replica_count > 1 the remainder will be
@@ -1960,6 +1978,7 @@ def run(
19601978
worker_pool_specs=worker_pool_specs,
19611979
managed_model=managed_model,
19621980
args=args,
1981+
environment_variables=environment_variables,
19631982
base_output_dir=base_output_dir,
19641983
service_account=service_account,
19651984
bigquery_destination=bigquery_destination,
@@ -1986,6 +2005,7 @@ def _run(
19862005
worker_pool_specs: _DistributedTrainingSpec,
19872006
managed_model: Optional[gca_model.Model] = None,
19882007
args: Optional[List[Union[str, float, int]]] = None,
2008+
environment_variables: Optional[Dict[str, str]] = None,
19892009
base_output_dir: Optional[str] = None,
19902010
service_account: Optional[str] = None,
19912011
bigquery_destination: Optional[str] = None,
@@ -2018,9 +2038,26 @@ def _run(
20182038
Model proto if this script produces a Managed Model.
20192039
args (List[Unions[str, int, float]]):
20202040
Command line arguments to be passed to the Python script.
2041+
environment_variables (Dict[str, str]):
2042+
Environment variables to be passed to the container.
2043+
Should be a dictionary where keys are environment variable names
2044+
and values are environment variable values for those names.
2045+
At most 10 environment variables can be specified.
2046+
The Name of the environment variable must be unique.
2047+
2048+
environment_variables = {
2049+
'MY_KEY': 'MY_VALUE'
2050+
}
20212051
base_output_dir (str):
20222052
GCS output directory of job. If not provided a
20232053
timestamped directory in the staging directory will be used.
2054+
2055+
AI Platform sets the following environment variables when it runs your training code:
2056+
2057+
- AIP_MODEL_DIR: a Cloud Storage URI of a directory intended for saving model artifacts, i.e. <base_output_dir>/model/
2058+
- AIP_CHECKPOINT_DIR: a Cloud Storage URI of a directory intended for saving checkpoints, i.e. <base_output_dir>/checkpoints/
2059+
- AIP_TENSORBOARD_LOG_DIR: a Cloud Storage URI of a directory intended for saving TensorBoard logs, i.e. <base_output_dir>/logs/
2060+
20242061
service_account (str):
20252062
Specifies the service account for workload run-as account.
20262063
Users submitting jobs must have act-as permission on this run-as account.
@@ -2083,6 +2120,13 @@ def _run(
20832120
if args:
20842121
spec["pythonPackageSpec"]["args"] = args
20852122

2123+
if environment_variables:
2124+
env = [
2125+
gca_env_var.EnvVar(name=str(key), value=str(value))
2126+
for key, value in environment_variables.items()
2127+
]
2128+
spec["pythonPackageSpec"]["env"] = env
2129+
20862130
(
20872131
training_task_inputs,
20882132
base_output_dir,
@@ -2334,6 +2378,7 @@ def run(
23342378
service_account: Optional[str] = None,
23352379
bigquery_destination: Optional[str] = None,
23362380
args: Optional[List[Union[str, float, int]]] = None,
2381+
environment_variables: Optional[Dict[str, str]] = None,
23372382
replica_count: int = 0,
23382383
machine_type: str = "n1-standard-4",
23392384
accelerator_type: str = "ACCELERATOR_TYPE_UNSPECIFIED",
@@ -2402,6 +2447,13 @@ def run(
24022447
base_output_dir (str):
24032448
GCS output directory of job. If not provided a
24042449
timestamped directory in the staging directory will be used.
2450+
2451+
AI Platform sets the following environment variables when it runs your training code:
2452+
2453+
- AIP_MODEL_DIR: a Cloud Storage URI of a directory intended for saving model artifacts, i.e. <base_output_dir>/model/
2454+
- AIP_CHECKPOINT_DIR: a Cloud Storage URI of a directory intended for saving checkpoints, i.e. <base_output_dir>/checkpoints/
2455+
- AIP_TENSORBOARD_LOG_DIR: a Cloud Storage URI of a directory intended for saving TensorBoard logs, i.e. <base_output_dir>/logs/
2456+
24052457
service_account (str):
24062458
Specifies the service account for workload run-as account.
24072459
Users submitting jobs must have act-as permission on this run-as account.
@@ -2422,6 +2474,16 @@ def run(
24222474
- AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test"
24232475
args (List[Unions[str, int, float]]):
24242476
Command line arguments to be passed to the Python script.
2477+
environment_variables (Dict[str, str]):
2478+
Environment variables to be passed to the container.
2479+
Should be a dictionary where keys are environment variable names
2480+
and values are environment variable values for those names.
2481+
At most 10 environment variables can be specified.
2482+
The Name of the environment variable must be unique.
2483+
2484+
environment_variables = {
2485+
'MY_KEY': 'MY_VALUE'
2486+
}
24252487
replica_count (int):
24262488
The number of worker replicas. If replica count = 1 then one chief
24272489
replica will be provisioned. If replica_count > 1 the remainder will be
@@ -2481,6 +2543,7 @@ def run(
24812543
worker_pool_specs=worker_pool_specs,
24822544
managed_model=managed_model,
24832545
args=args,
2546+
environment_variables=environment_variables,
24842547
base_output_dir=base_output_dir,
24852548
service_account=service_account,
24862549
bigquery_destination=bigquery_destination,
@@ -2506,6 +2569,7 @@ def _run(
25062569
worker_pool_specs: _DistributedTrainingSpec,
25072570
managed_model: Optional[gca_model.Model] = None,
25082571
args: Optional[List[Union[str, float, int]]] = None,
2572+
environment_variables: Optional[Dict[str, str]] = None,
25092573
base_output_dir: Optional[str] = None,
25102574
service_account: Optional[str] = None,
25112575
bigquery_destination: Optional[str] = None,
@@ -2535,9 +2599,26 @@ def _run(
25352599
Model proto if this script produces a Managed Model.
25362600
args (List[Unions[str, int, float]]):
25372601
Command line arguments to be passed to the Python script.
2602+
environment_variables (Dict[str, str]):
2603+
Environment variables to be passed to the container.
2604+
Should be a dictionary where keys are environment variable names
2605+
and values are environment variable values for those names.
2606+
At most 10 environment variables can be specified.
2607+
The Name of the environment variable must be unique.
2608+
2609+
environment_variables = {
2610+
'MY_KEY': 'MY_VALUE'
2611+
}
25382612
base_output_dir (str):
25392613
GCS output directory of job. If not provided a
25402614
timestamped directory in the staging directory will be used.
2615+
2616+
AI Platform sets the following environment variables when it runs your training code:
2617+
2618+
- AIP_MODEL_DIR: a Cloud Storage URI of a directory intended for saving model artifacts, i.e. <base_output_dir>/model/
2619+
- AIP_CHECKPOINT_DIR: a Cloud Storage URI of a directory intended for saving checkpoints, i.e. <base_output_dir>/checkpoints/
2620+
- AIP_TENSORBOARD_LOG_DIR: a Cloud Storage URI of a directory intended for saving TensorBoard logs, i.e. <base_output_dir>/logs/
2621+
25412622
service_account (str):
25422623
Specifies the service account for workload run-as account.
25432624
Users submitting jobs must have act-as permission on this run-as account.
@@ -2593,6 +2674,13 @@ def _run(
25932674
if args:
25942675
spec["containerSpec"]["args"] = args
25952676

2677+
if environment_variables:
2678+
env = [
2679+
gca_env_var.EnvVar(name=str(key), value=str(value))
2680+
for key, value in environment_variables.items()
2681+
]
2682+
spec["containerSpec"]["env"] = env
2683+
25962684
(
25972685
training_task_inputs,
25982686
base_output_dir,
@@ -3625,6 +3713,7 @@ def run(
36253713
service_account: Optional[str] = None,
36263714
bigquery_destination: Optional[str] = None,
36273715
args: Optional[List[Union[str, float, int]]] = None,
3716+
environment_variables: Optional[Dict[str, str]] = None,
36283717
replica_count: int = 0,
36293718
machine_type: str = "n1-standard-4",
36303719
accelerator_type: str = "ACCELERATOR_TYPE_UNSPECIFIED",
@@ -3693,6 +3782,13 @@ def run(
36933782
base_output_dir (str):
36943783
GCS output directory of job. If not provided a
36953784
timestamped directory in the staging directory will be used.
3785+
3786+
AI Platform sets the following environment variables when it runs your training code:
3787+
3788+
- AIP_MODEL_DIR: a Cloud Storage URI of a directory intended for saving model artifacts, i.e. <base_output_dir>/model/
3789+
- AIP_CHECKPOINT_DIR: a Cloud Storage URI of a directory intended for saving checkpoints, i.e. <base_output_dir>/checkpoints/
3790+
- AIP_TENSORBOARD_LOG_DIR: a Cloud Storage URI of a directory intended for saving TensorBoard logs, i.e. <base_output_dir>/logs/
3791+
36963792
service_account (str):
36973793
Specifies the service account for workload run-as account.
36983794
Users submitting jobs must have act-as permission on this run-as account.
@@ -3713,6 +3809,16 @@ def run(
37133809
- AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test"
37143810
args (List[Unions[str, int, float]]):
37153811
Command line arguments to be passed to the Python script.
3812+
environment_variables (Dict[str, str]):
3813+
Environment variables to be passed to the container.
3814+
Should be a dictionary where keys are environment variable names
3815+
and values are environment variable values for those names.
3816+
At most 10 environment variables can be specified.
3817+
The Name of the environment variable must be unique.
3818+
3819+
environment_variables = {
3820+
'MY_KEY': 'MY_VALUE'
3821+
}
37163822
replica_count (int):
37173823
The number of worker replicas. If replica count = 1 then one chief
37183824
replica will be provisioned. If replica_count > 1 the remainder will be
@@ -3767,6 +3873,7 @@ def run(
37673873
worker_pool_specs=worker_pool_specs,
37683874
managed_model=managed_model,
37693875
args=args,
3876+
environment_variables=environment_variables,
37703877
base_output_dir=base_output_dir,
37713878
service_account=service_account,
37723879
training_fraction_split=training_fraction_split,
@@ -3792,6 +3899,7 @@ def _run(
37923899
worker_pool_specs: _DistributedTrainingSpec,
37933900
managed_model: Optional[gca_model.Model] = None,
37943901
args: Optional[List[Union[str, float, int]]] = None,
3902+
environment_variables: Optional[Dict[str, str]] = None,
37953903
base_output_dir: Optional[str] = None,
37963904
service_account: Optional[str] = None,
37973905
training_fraction_split: float = 0.8,
@@ -3822,9 +3930,26 @@ def _run(
38223930
Model proto if this script produces a Managed Model.
38233931
args (List[Unions[str, int, float]]):
38243932
Command line arguments to be passed to the Python script.
3933+
environment_variables (Dict[str, str]):
3934+
Environment variables to be passed to the container.
3935+
Should be a dictionary where keys are environment variable names
3936+
and values are environment variable values for those names.
3937+
At most 10 environment variables can be specified.
3938+
The Name of the environment variable must be unique.
3939+
3940+
environment_variables = {
3941+
'MY_KEY': 'MY_VALUE'
3942+
}
38253943
base_output_dir (str):
38263944
GCS output directory of job. If not provided a
38273945
timestamped directory in the staging directory will be used.
3946+
3947+
AI Platform sets the following environment variables when it runs your training code:
3948+
3949+
- AIP_MODEL_DIR: a Cloud Storage URI of a directory intended for saving model artifacts, i.e. <base_output_dir>/model/
3950+
- AIP_CHECKPOINT_DIR: a Cloud Storage URI of a directory intended for saving checkpoints, i.e. <base_output_dir>/checkpoints/
3951+
- AIP_TENSORBOARD_LOG_DIR: a Cloud Storage URI of a directory intended for saving TensorBoard logs, i.e. <base_output_dir>/logs/
3952+
38283953
service_account (str):
38293954
Specifies the service account for workload run-as account.
38303955
Users submitting jobs must have act-as permission on this run-as account.
@@ -3866,6 +3991,13 @@ def _run(
38663991
if args:
38673992
spec["pythonPackageSpec"]["args"] = args
38683993

3994+
if environment_variables:
3995+
env = [
3996+
gca_env_var.EnvVar(name=str(key), value=str(value))
3997+
for key, value in environment_variables.items()
3998+
]
3999+
spec["pythonPackageSpec"]["env"] = env
4000+
38694001
(
38704002
training_task_inputs,
38714003
base_output_dir,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.