@@ -122,6 +122,7 @@ def _create_input_data_config( |
122 | 122 | test_fraction_split: float = 0.1, |
123 | 123 | predefined_split_column_name: Optional[str] = None, |
124 | 124 | gcs_destination_uri_prefix: Optional[str] = None, |
| 125 | + bigquery_destination: Optional[str] = None, |
125 | 126 | ) -> Optional[gca_training_pipeline.InputDataConfig]: |
126 | 127 | """Constructs a input data config to pass to the training pipeline. |
127 | 128 |
|
@@ -160,6 +161,20 @@ def _create_input_data_config( |
160 | 161 | - AIP_TRAINING_DATA_URI = "gcs_destination/training-*" |
161 | 162 | - AIP_VALIDATION_DATA_URI = "gcs_destination/validation-*" |
162 | 163 | - AIP_TEST_DATA_URI = "gcs_destination/test-*". |
| 164 | + bigquery_destination (str): |
| 165 | + The BigQuery project location where the training data is to |
| 166 | + be written to. In the given project a new dataset is created |
| 167 | + with name |
| 168 | + ``dataset_<dataset-id>_<annotation-type>_<timestamp-of-training-call>`` |
| 169 | + where timestamp is in YYYY_MM_DDThh_mm_ss_sssZ format. All |
| 170 | + training input data will be written into that dataset. In |
| 171 | + the dataset three tables will be created, ``training``, |
| 172 | + ``validation`` and ``test``. |
| 173 | +
|
| 174 | + - AIP_DATA_FORMAT = "bigquery". |
| 175 | + - AIP_TRAINING_DATA_URI ="bigquery_destination.dataset_*.training" |
| 176 | + - AIP_VALIDATION_DATA_URI = "bigquery_destination.dataset_*.validation" |
| 177 | + - AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test" |
163 | 178 | """ |
164 | 179 |
|
165 | 180 | input_data_config = None |
@@ -193,12 +208,20 @@ def _create_input_data_config( |
193 | 208 | output_uri_prefix=gcs_destination_uri_prefix |
194 | 209 | ) |
195 | 210 |
|
| 211 | + # TODO(b/177416223) validate managed BQ dataset is passed in |
| 212 | + bigquery_destination_proto = None |
| 213 | + if bigquery_destination: |
| 214 | + bigquery_destination_proto = gca_io.BigQueryDestination( |
| 215 | + output_uri=bigquery_destination |
| 216 | + ) |
| 217 | + |
196 | 218 | # create input data config |
197 | 219 | input_data_config = gca_training_pipeline.InputDataConfig( |
198 | 220 | fraction_split=fraction_split, |
199 | 221 | predefined_split=predefined_split, |
200 | 222 | dataset_id=dataset.name, |
201 | 223 | gcs_destination=gcs_destination, |
| 224 | + bigquery_destination=bigquery_destination_proto, |
202 | 225 | ) |
203 | 226 |
|
204 | 227 | return input_data_config |
@@ -214,6 +237,7 @@ def _run_job( |
214 | 237 | predefined_split_column_name: Optional[str] = None, |
215 | 238 | model: Optional[gca_model.Model] = None, |
216 | 239 | gcs_destination_uri_prefix: Optional[str] = None, |
| 240 | + bigquery_destination: Optional[str] = None, |
217 | 241 | ) -> Optional[models.Model]: |
218 | 242 | """Runs the training job. |
219 | 243 |
|
@@ -295,6 +319,20 @@ def _run_job( |
295 | 319 | - AIP_TRAINING_DATA_URI = "gcs_destination/training-*" |
296 | 320 | - AIP_VALIDATION_DATA_URI = "gcs_destination/validation-*" |
297 | 321 | - AIP_TEST_DATA_URI = "gcs_destination/test-*". |
| 322 | + bigquery_destination (str): |
| 323 | + The BigQuery project location where the training data is to |
| 324 | + be written to. In the given project a new dataset is created |
| 325 | + with name |
| 326 | + ``dataset_<dataset-id>_<annotation-type>_<timestamp-of-training-call>`` |
| 327 | + where timestamp is in YYYY_MM_DDThh_mm_ss_sssZ format. All |
| 328 | + training input data will be written into that dataset. In |
| 329 | + the dataset three tables will be created, ``training``, |
| 330 | + ``validation`` and ``test``. |
| 331 | +
|
| 332 | + - AIP_DATA_FORMAT = "bigquery". |
| 333 | + - AIP_TRAINING_DATA_URI ="bigquery_destination.dataset_*.training" |
| 334 | + - AIP_VALIDATION_DATA_URI = "bigquery_destination.dataset_*.validation" |
| 335 | + - AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test" |
298 | 336 | """ |
299 | 337 |
|
300 | 338 | input_data_config = self._create_input_data_config( |
@@ -304,6 +342,7 @@ def _run_job( |
304 | 342 | test_fraction_split=test_fraction_split, |
305 | 343 | predefined_split_column_name=predefined_split_column_name, |
306 | 344 | gcs_destination_uri_prefix=gcs_destination_uri_prefix, |
| 345 | + bigquery_destination=bigquery_destination, |
307 | 346 | ) |
308 | 347 |
|
309 | 348 | # create training pipeline |
@@ -1418,6 +1457,7 @@ def run( |
1418 | 1457 | dataset: Optional[datasets.Dataset] = None, |
1419 | 1458 | model_display_name: Optional[str] = None, |
1420 | 1459 | base_output_dir: Optional[str] = None, |
| 1460 | + bigquery_destination: Optional[str] = None, |
1421 | 1461 | args: Optional[List[Union[str, float, int]]] = None, |
1422 | 1462 | replica_count: int = 0, |
1423 | 1463 | machine_type: str = "n1-standard-4", |
@@ -1463,6 +1503,21 @@ def run( |
1463 | 1503 | base_output_dir (str): |
1464 | 1504 | GCS output directory of job. If not provided a |
1465 | 1505 | timestamped directory in the staging directory will be used. |
| 1506 | + bigquery_destination (str): |
| 1507 | + Provide this field if `dataset` is a BiqQuery dataset. |
| 1508 | + The BigQuery project location where the training data is to |
| 1509 | + be written to. In the given project a new dataset is created |
| 1510 | + with name |
| 1511 | + ``dataset_<dataset-id>_<annotation-type>_<timestamp-of-training-call>`` |
| 1512 | + where timestamp is in YYYY_MM_DDThh_mm_ss_sssZ format. All |
| 1513 | + training input data will be written into that dataset. In |
| 1514 | + the dataset three tables will be created, ``training``, |
| 1515 | + ``validation`` and ``test``. |
| 1516 | +
|
| 1517 | + - AIP_DATA_FORMAT = "bigquery". |
| 1518 | + - AIP_TRAINING_DATA_URI ="bigquery_destination.dataset_*.training" |
| 1519 | + - AIP_VALIDATION_DATA_URI = "bigquery_destination.dataset_*.validation" |
| 1520 | + - AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test" |
1466 | 1521 | args (List[Unions[str, int, float]]): |
1467 | 1522 | Command line arguments to be passed to the Python script. |
1468 | 1523 | replica_count (int): |
@@ -1815,6 +1870,7 @@ def run( |
1815 | 1870 | dataset: Optional[datasets.Dataset] = None, |
1816 | 1871 | model_display_name: Optional[str] = None, |
1817 | 1872 | base_output_dir: Optional[str] = None, |
| 1873 | + bigquery_destination: Optional[str] = None, |
1818 | 1874 | args: Optional[List[Union[str, float, int]]] = None, |
1819 | 1875 | replica_count: int = 0, |
1820 | 1876 | machine_type: str = "n1-standard-4", |
@@ -1844,7 +1900,7 @@ def run( |
1844 | 1900 | Args: |
1845 | 1901 | dataset (aiplatform.Dataset): |
1846 | 1902 | AI Platform to fit this training against. Custom training script should |
1847 | | - retrieve datasets through passed in environement variables uris: |
| 1903 | + retrieve datasets through passed in environment variables uris: |
1848 | 1904 |
|
1849 | 1905 | os.environ["AIP_TRAINING_DATA_URI"] |
1850 | 1906 | os.environ["AIP_VALIDATION_DATA_URI"] |
@@ -1860,6 +1916,21 @@ def run( |
1860 | 1916 | base_output_dir (str): |
1861 | 1917 | GCS output directory of job. If not provided a |
1862 | 1918 | timestamped directory in the staging directory will be used. |
| 1919 | + bigquery_destination (str): |
| 1920 | + Provide this field if `dataset` is a BiqQuery dataset. |
| 1921 | + The BigQuery project location where the training data is to |
| 1922 | + be written to. In the given project a new dataset is created |
| 1923 | + with name |
| 1924 | + ``dataset_<dataset-id>_<annotation-type>_<timestamp-of-training-call>`` |
| 1925 | + where timestamp is in YYYY_MM_DDThh_mm_ss_sssZ format. All |
| 1926 | + training input data will be written into that dataset. In |
| 1927 | + the dataset three tables will be created, ``training``, |
| 1928 | + ``validation`` and ``test``. |
| 1929 | +
|
| 1930 | + - AIP_DATA_FORMAT = "bigquery". |
| 1931 | + - AIP_TRAINING_DATA_URI ="bigquery_destination.dataset_*.training" |
| 1932 | + - AIP_VALIDATION_DATA_URI = "bigquery_destination.dataset_*.validation" |
| 1933 | + - AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test" |
1863 | 1934 | args (List[Unions[str, int, float]]): |
1864 | 1935 | Command line arguments to be passed to the Python script. |
1865 | 1936 | replica_count (int): |
@@ -1921,6 +1992,7 @@ def run( |
1921 | 1992 | managed_model=managed_model, |
1922 | 1993 | args=args, |
1923 | 1994 | base_output_dir=base_output_dir, |
| 1995 | + bigquery_destination=bigquery_destination, |
1924 | 1996 | training_fraction_split=training_fraction_split, |
1925 | 1997 | validation_fraction_split=validation_fraction_split, |
1926 | 1998 | test_fraction_split=test_fraction_split, |
@@ -1936,6 +2008,7 @@ def _run( |
1936 | 2008 | managed_model: Optional[gca_model.Model] = None, |
1937 | 2009 | args: Optional[List[Union[str, float, int]]] = None, |
1938 | 2010 | base_output_dir: Optional[str] = None, |
| 2011 | + bigquery_destination: Optional[str] = None, |
1939 | 2012 | training_fraction_split: float = 0.8, |
1940 | 2013 | validation_fraction_split: float = 0.1, |
1941 | 2014 | test_fraction_split: float = 0.1, |
@@ -1955,6 +2028,20 @@ def _run( |
1955 | 2028 | base_output_dir (str): |
1956 | 2029 | GCS output directory of job. If not provided a |
1957 | 2030 | timestamped directory in the staging directory will be used. |
| 2031 | + bigquery_destination (str): |
| 2032 | + The BigQuery project location where the training data is to |
| 2033 | + be written to. In the given project a new dataset is created |
| 2034 | + with name |
| 2035 | + ``dataset_<dataset-id>_<annotation-type>_<timestamp-of-training-call>`` |
| 2036 | + where timestamp is in YYYY_MM_DDThh_mm_ss_sssZ format. All |
| 2037 | + training input data will be written into that dataset. In |
| 2038 | + the dataset three tables will be created, ``training``, |
| 2039 | + ``validation`` and ``test``. |
| 2040 | +
|
| 2041 | + - AIP_DATA_FORMAT = "bigquery". |
| 2042 | + - AIP_TRAINING_DATA_URI ="bigquery_destination.dataset_*.training" |
| 2043 | + - AIP_VALIDATION_DATA_URI = "bigquery_destination.dataset_*.validation" |
| 2044 | + - AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test" |
1958 | 2045 | training_fraction_split (float): |
1959 | 2046 | The fraction of the input data that is to be |
1960 | 2047 | used to train the Model. |
@@ -2010,6 +2097,7 @@ def _run( |
2010 | 2097 | predefined_split_column_name=predefined_split_column_name, |
2011 | 2098 | model=managed_model, |
2012 | 2099 | gcs_destination_uri_prefix=base_output_dir, |
| 2100 | + bigquery_destination=bigquery_destination, |
2013 | 2101 | ) |
2014 | 2102 |
|
2015 | 2103 | return model |
|