צור צינור TFX באמצעות תבניות

מבוא

מסמך זה יספק הוראות ליצירת TensorFlow המורחב (TFX) צינור באמצעות תבניות אשר מסופקות עם חבילת TFX Python. רבות מההוראות הן פקודות מעטפת של לינוקס, שיפעלו על מופע AI Platform Notebooks. מקבילים תאים קוד מחברת Jupyter אשר באוזניכם את הפקודות באמצעות ! מסופקים.

תוכלו לבנות צינור באמצעות מוניות Trips הנתונים שפורסמו על ידי עיריית שיקגו. אנו ממליצים לך בחום לנסות לבנות צינור משלך באמצעות מערך הנתונים שלך על ידי שימוש בצינור זה כבסיס.

שלב 1. הגדר את הסביבה שלך.

AI Platform Pipelines יכין סביבת פיתוח לבניית צינור, ומקבץ Kubeflow Pipeline להפעלת הצינור החדש שנבנה.

תקן tfx חבילת python עם kfp דרישה נוספת.

import sys
# Use the latest version of pip.
!pip install --upgrade pip
# Install tfx and kfp Python packages.
!pip install --upgrade "tfx[kfp]<2"

בוא נבדוק את הגרסאות של TFX.

python3 -c "from tfx import version ; print('TFX version: {}'.format(version.__version__))"
TFX version: 0.29.0

בצינורות פלטפורמה AI, TFX פועל בסביבה Kubernetes אירח באמצעות Kubeflow צנרת .

בואו נגדיר כמה משתני סביבה לשימוש ב-Kubeflow Pipelines.

ראשית, קבל את מזהה פרויקט GCP שלך.

# Read GCP project id from env.
shell_output=!gcloud config list --format 'value(core.project)' 2>/dev/null
GOOGLE_CLOUD_PROJECT=shell_output[0]
%env GOOGLE_CLOUD_PROJECT={GOOGLE_CLOUD_PROJECT}
print("GCP project ID:" + GOOGLE_CLOUD_PROJECT)
env: GOOGLE_CLOUD_PROJECT=tf-benchmark-dashboard
GCP project ID:tf-benchmark-dashboard

אנחנו צריכים גם לגשת לאשכול ה-KFP שלך. אתה יכול לגשת אליו ב-Google Cloud Console שלך ​​בתפריט "AI Platform > Pipeline". ניתן למצוא את "נקודת הקצה" של אשכול KFP מכתובת ה-URL של לוח המחוונים של Pipelines, או שתוכל לקבל אותה מכתובת ה-URL של דף ההתחלה שבו השקת מחברת זו. בואו ליצור ENDPOINT משתנה סביבה ולהגדיר אותו לנקודת קצה אשכול KFP. ENDPOINT צריך להכיל רק את החלק של שם המארח של כתובת האתר. לדוגמה, אם כתובת ה- URL של לוח המחוונים KFP הוא <a href="https://1e9deb537390ca22-dot-asia-east1.pipelines.googleusercontent.com/#/start">https://1e9deb537390ca22-dot-asia-east1.pipelines.googleusercontent.com/#/start</a> , ערך Endpoint הופך 1e9deb537390ca22-dot-asia-east1.pipelines.googleusercontent.com .

# This refers to the KFP cluster endpoint
ENDPOINT='' # Enter your ENDPOINT here.
if not ENDPOINT:
    from absl import logging
    logging.error('Set your ENDPOINT in this cell.')
ERROR:absl:Set your ENDPOINT in this cell.

הגדר את שם התמונה כפי tfx-pipeline תחת פרויקט GCP הנוכחי.

# Docker image name for the pipeline image.
CUSTOM_TFX_IMAGE='gcr.io/' + GOOGLE_CLOUD_PROJECT + '/tfx-pipeline'

וכן, זה נעשה. אנחנו מוכנים ליצור צינור.

שלב 2. העתק את התבנית המוגדרת מראש לספריית הפרויקט שלך.

בשלב זה, ניצור ספריה וקבצים של פרויקט צינור עובד על ידי העתקת קבצים נוספים מתבנית מוגדרת מראש.

אתה יכול לתת הצינור שלך בשם אחר על ידי שינוי PIPELINE_NAME להלן. זה יהפוך גם לשם של ספריית הפרויקט שבה יוכנסו הקבצים שלך.

PIPELINE_NAME="my_pipeline"
import os
PROJECT_DIR=os.path.join(os.path.expanduser("~"),"imported",PIPELINE_NAME)

TFX כולל את taxi תבנית עם חבילת python TFX. אם אתה מתכנן לפתור בעיית חיזוי נקודתית, כולל סיווג ורגרסיה, תבנית זו יכולה לשמש כנקודת התחלה.

tfx template copy עותקים פקודת CLI מוגדרים מראש קבצי התבנית לתוך ספריית הפרויקט שלך.

!tfx template copy \
  --pipeline-name={PIPELINE_NAME} \
  --destination-path={PROJECT_DIR} \
  --model=taxi
CLI
Copying taxi pipeline template
kubeflow_runner.py -> /home/kbuilder/imported/my_pipeline/kubeflow_runner.py
kubeflow_v2_dag_runner.py -> /home/kbuilder/imported/my_pipeline/kubeflow_v2_dag_runner.py
features_test.py -> /home/kbuilder/imported/my_pipeline/models/features_test.py
model_test.py -> /home/kbuilder/imported/my_pipeline/models/estimator/model_test.py
constants.py -> /home/kbuilder/imported/my_pipeline/models/estimator/constants.py
model.py -> /home/kbuilder/imported/my_pipeline/models/estimator/model.py
__init__.py -> /home/kbuilder/imported/my_pipeline/models/estimator/__init__.py
model_test.py -> /home/kbuilder/imported/my_pipeline/models/keras/model_test.py
constants.py -> /home/kbuilder/imported/my_pipeline/models/keras/constants.py
model.py -> /home/kbuilder/imported/my_pipeline/models/keras/model.py
__init__.py -> /home/kbuilder/imported/my_pipeline/models/keras/__init__.py
preprocessing_test.py -> /home/kbuilder/imported/my_pipeline/models/preprocessing_test.py
preprocessing.py -> /home/kbuilder/imported/my_pipeline/models/preprocessing.py
__init__.py -> /home/kbuilder/imported/my_pipeline/models/__init__.py
features.py -> /home/kbuilder/imported/my_pipeline/models/features.py
pipeline.py -> /home/kbuilder/imported/my_pipeline/pipeline/pipeline.py
configs.py -> /home/kbuilder/imported/my_pipeline/pipeline/configs.py
__init__.py -> /home/kbuilder/imported/my_pipeline/pipeline/__init__.py
local_runner.py -> /home/kbuilder/imported/my_pipeline/local_runner.py
model_analysis.ipynb -> /home/kbuilder/imported/my_pipeline/model_analysis.ipynb
__init__.py -> /home/kbuilder/imported/my_pipeline/__init__.py
data_validation.ipynb -> /home/kbuilder/imported/my_pipeline/data_validation.ipynb
.gitignore -> /home/kbuilder/imported/my_pipeline/.gitignore
Traceback (most recent call last):
  File "/tmpfs/src/tf_docs_env/bin/tfx", line 8, in <module>
    sys.exit(cli_group())
  File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/tfx/tools/cli/commands/template.py", line 73, in copy
    template_handler.copy_template(ctx.flags_dict)
  File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/tfx/tools/cli/handler/template_handler.py", line 185, in copy_template
    fileio.copy(src_path, dst_path)
  File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/tfx/dsl/io/fileio.py", line 51, in copy
    src_fs.copy(src, dst, overwrite=overwrite)
  File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/tfx/dsl/io/plugins/tensorflow_gfile.py", line 48, in copy
    tf.io.gfile.copy(src, dst, overwrite=overwrite)
  File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/tensorflow/python/lib/io/file_io.py", line 516, in copy_v2
    compat.path_to_bytes(src), compat.path_to_bytes(dst), overwrite)
tensorflow.python.framework.errors_impl.AlreadyExistsError: file already exists

שנה את ההקשר של ספריית העבודה במחברת זו לספריית הפרויקט.

%cd {PROJECT_DIR}
/home/kbuilder/imported/my_pipeline

שלב 3. עיין בקבצי המקור שהועתקו

תבנית TFX מספקת קבצי פיגום בסיסיים לבניית צינור, כולל קוד מקור של Python, נתונים לדוגמה ומחברות Jupyter לניתוח הפלט של הצינור. taxi התבנית משתמשת במערך הזהה שיקגו מוניות מודל ML כמו הדרכת Airflow .

הנה מבוא קצר לכל אחד מקבצי Python.

  • pipeline - מדריך זה מכיל את ההגדרה של הצינור
    • configs.py - מגדיר קבוע נפוצות לרצי צינור
    • pipeline.py - מגדיר רכיבי TFX וצנרת
  • models - ספרייה זו מכילה הגדרות מודל ML.
    • features.py , features_test.py - מגדיר את התכונות של מודל
    • preprocessing.py , preprocessing_test.py - מגדיר עיבוד מקדים עבודות באמצעות tf::Transform
    • estimator - ספרייה זו מכילה מודל המבוסס הערכה.
      • constants.py - מגדיר קבוע של המודל
      • model.py , model_test.py - מגדיר מודל DNN שימוש במעריך TF
    • keras - ספריה זו מכילה מודל המבוסס Keras.
      • constants.py - מגדיר קבוע של המודל
      • model.py , model_test.py - מגדיר מודל DNN באמצעות Keras
  • local_runner.py , kubeflow_runner.py - מגדירים הרצים עבור כל מנוע תזמור

ייתכן שתבחין כי יש כמה קבצים עם _test.py בשמם. אלו הן בדיקות יחידה של הצינור ומומלץ להוסיף בדיקות יחידות נוספות ככל שתטמיעו צינורות משלכם. אתה יכול להריץ בדיקות יחידות על ידי אספקת שם המודול של קבצי בדיקה עם -m דגל. בדרך כלל אפשר לקבל שם מודול ידי מחיקת .py רחבה והחלפה / עם . . לדוגמה:

{sys.executable} -m models.features_test
{sys.executable} -m models.keras.model_test
Running tests under Python 3.7.5: /tmpfs/src/tf_docs_env/bin/python
[ RUN      ] FeaturesTest.testNumberOfBucketFeatureBucketCount
INFO:tensorflow:time(__main__.FeaturesTest.testNumberOfBucketFeatureBucketCount): 0.0s
I1204 11:33:54.064224 139808961349440 test_util.py:2076] time(__main__.FeaturesTest.testNumberOfBucketFeatureBucketCount): 0.0s
[       OK ] FeaturesTest.testNumberOfBucketFeatureBucketCount
[ RUN      ] FeaturesTest.testTransformedNames
INFO:tensorflow:time(__main__.FeaturesTest.testTransformedNames): 0.0s
I1204 11:33:54.064666 139808961349440 test_util.py:2076] time(__main__.FeaturesTest.testTransformedNames): 0.0s
[       OK ] FeaturesTest.testTransformedNames
[ RUN      ] FeaturesTest.test_session
[  SKIPPED ] FeaturesTest.test_session
----------------------------------------------------------------------
Ran 3 tests in 0.001s

OK (skipped=1)
Running tests under Python 3.7.5: /tmpfs/src/tf_docs_env/bin/python
[ RUN      ] ModelTest.testBuildKerasModel
2021-12-04 11:33:57.507456: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'libcusolver.so.10'; dlerror: libcusolver.so.10: cannot open shared object file: No such file or directory
2021-12-04 11:33:57.508566: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1757] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
I1204 11:33:57.581331 139740839778112 layer_utils.py:191] Model: "model"
I1204 11:33:57.581501 139740839778112 layer_utils.py:192] __________________________________________________________________________________________________
I1204 11:33:57.581558 139740839778112 layer_utils.py:189] Layer (type)                    Output Shape         Param #     Connected to                     
I1204 11:33:57.581596 139740839778112 layer_utils.py:194] ==================================================================================================
I1204 11:33:57.581741 139740839778112 layer_utils.py:189] pickup_latitude_xf (InputLayer) [(None,)]            0                                            
I1204 11:33:57.581793 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.581883 139740839778112 layer_utils.py:189] trip_miles_xf (InputLayer)      [(None,)]            0                                            
I1204 11:33:57.581926 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.582010 139740839778112 layer_utils.py:189] trip_start_hour_xf (InputLayer) [(None,)]            0                                            
I1204 11:33:57.582052 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.582189 139740839778112 layer_utils.py:189] dense_features (DenseFeatures)  (None, 1)            0           pickup_latitude_xf[0][0]         
I1204 11:33:57.582241 139740839778112 layer_utils.py:189]                                                                  trip_miles_xf[0][0]              
I1204 11:33:57.582280 139740839778112 layer_utils.py:189]                                                                  trip_start_hour_xf[0][0]         
I1204 11:33:57.582315 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.582462 139740839778112 layer_utils.py:189] dense (Dense)                   (None, 1)            2           dense_features[0][0]             
I1204 11:33:57.582518 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.582629 139740839778112 layer_utils.py:189] dense_1 (Dense)                 (None, 1)            2           dense[0][0]                      
I1204 11:33:57.582674 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.582824 139740839778112 layer_utils.py:189] dense_features_1 (DenseFeatures (None, 34)           0           pickup_latitude_xf[0][0]         
I1204 11:33:57.582879 139740839778112 layer_utils.py:189]                                                                  trip_miles_xf[0][0]              
I1204 11:33:57.582921 139740839778112 layer_utils.py:189]                                                                  trip_start_hour_xf[0][0]         
I1204 11:33:57.582957 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.583053 139740839778112 layer_utils.py:189] concatenate (Concatenate)       (None, 35)           0           dense_1[0][0]                    
I1204 11:33:57.583099 139740839778112 layer_utils.py:189]                                                                  dense_features_1[0][0]           
I1204 11:33:57.583143 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.583260 139740839778112 layer_utils.py:189] dense_2 (Dense)                 (None, 1)            36          concatenate[0][0]                
I1204 11:33:57.583309 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.583389 139740839778112 layer_utils.py:189] tf.compat.v1.squeeze (TFOpLambd (None,)              0           dense_2[0][0]                    
I1204 11:33:57.583432 139740839778112 layer_utils.py:256] ==================================================================================================
I1204 11:33:57.583687 139740839778112 layer_utils.py:267] Total params: 40
I1204 11:33:57.583751 139740839778112 layer_utils.py:268] Trainable params: 40
I1204 11:33:57.583794 139740839778112 layer_utils.py:269] Non-trainable params: 0
I1204 11:33:57.583832 139740839778112 layer_utils.py:270] __________________________________________________________________________________________________
I1204 11:33:57.649701 139740839778112 layer_utils.py:191] Model: "model_1"
I1204 11:33:57.649825 139740839778112 layer_utils.py:192] __________________________________________________________________________________________________
I1204 11:33:57.649878 139740839778112 layer_utils.py:189] Layer (type)                    Output Shape         Param #     Connected to                     
I1204 11:33:57.649932 139740839778112 layer_utils.py:194] ==================================================================================================
I1204 11:33:57.650066 139740839778112 layer_utils.py:189] pickup_latitude_xf (InputLayer) [(None,)]            0                                            
I1204 11:33:57.650120 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.650207 139740839778112 layer_utils.py:189] trip_miles_xf (InputLayer)      [(None,)]            0                                            
I1204 11:33:57.650259 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.650356 139740839778112 layer_utils.py:189] trip_start_hour_xf (InputLayer) [(None,)]            0                                            
I1204 11:33:57.650398 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.650552 139740839778112 layer_utils.py:189] dense_features_2 (DenseFeatures (None, 1)            0           pickup_latitude_xf[0][0]         
I1204 11:33:57.650603 139740839778112 layer_utils.py:189]                                                                  trip_miles_xf[0][0]              
I1204 11:33:57.650644 139740839778112 layer_utils.py:189]                                                                  trip_start_hour_xf[0][0]         
I1204 11:33:57.650682 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.650812 139740839778112 layer_utils.py:189] dense_3 (Dense)                 (None, 1)            2           dense_features_2[0][0]           
I1204 11:33:57.650864 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.651007 139740839778112 layer_utils.py:189] dense_features_3 (DenseFeatures (None, 34)           0           pickup_latitude_xf[0][0]         
I1204 11:33:57.651061 139740839778112 layer_utils.py:189]                                                                  trip_miles_xf[0][0]              
I1204 11:33:57.651102 139740839778112 layer_utils.py:189]                                                                  trip_start_hour_xf[0][0]         
I1204 11:33:57.651146 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.651229 139740839778112 layer_utils.py:189] concatenate_1 (Concatenate)     (None, 35)           0           dense_3[0][0]                    
I1204 11:33:57.651274 139740839778112 layer_utils.py:189]                                                                  dense_features_3[0][0]           
I1204 11:33:57.651311 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.651462 139740839778112 layer_utils.py:189] dense_4 (Dense)                 (None, 1)            36          concatenate_1[0][0]              
I1204 11:33:57.651547 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________
I1204 11:33:57.651632 139740839778112 layer_utils.py:189] tf.compat.v1.squeeze_1 (TFOpLam (None,)              0           dense_4[0][0]                    
I1204 11:33:57.651675 139740839778112 layer_utils.py:256] ==================================================================================================
I1204 11:33:57.651959 139740839778112 layer_utils.py:267] Total params: 38
I1204 11:33:57.652019 139740839778112 layer_utils.py:268] Trainable params: 38
I1204 11:33:57.652061 139740839778112 layer_utils.py:269] Non-trainable params: 0
I1204 11:33:57.652098 139740839778112 layer_utils.py:270] __________________________________________________________________________________________________
INFO:tensorflow:time(__main__.ModelTest.testBuildKerasModel): 0.84s
I1204 11:33:57.652639 139740839778112 test_util.py:2076] time(__main__.ModelTest.testBuildKerasModel): 0.84s
[       OK ] ModelTest.testBuildKerasModel
[ RUN      ] ModelTest.test_session
[  SKIPPED ] ModelTest.test_session
----------------------------------------------------------------------
Ran 2 tests in 0.836s

OK (skipped=1)

שלב 4. הפעל את צינור ה-TFX הראשון שלך

רכיבים בצנרת TFX יפיקו יציאות עבור כול מחזור כמו חפצי Metadata ML , והם צריכים להיות מאוחסנים במקום כלשהו. אתה יכול להשתמש בכל אחסון שאליו ניתן לגשת לאשכול KFP, ולדוגמה זו נשתמש ב-Google Cloud Storage (GCS). דלי GCS כברירת מחדל צריך היה להיווצר באופן אוטומטי. שמו יהיה <your-project-id>-kubeflowpipelines-default .

בואו נעלה את נתוני הדוגמאות שלנו ל-GCS bucket כדי שנוכל להשתמש בהם בצינור שלנו מאוחר יותר.

gsutil cp data/data.csv gs://{GOOGLE_CLOUD_PROJECT}-kubeflowpipelines-default/tfx-template/data/taxi/data.csv
BucketNotFoundException: 404 gs://tf-benchmark-dashboard-kubeflowpipelines-default bucket does not exist.

בואו ליצור צינור TFX באמצעות tfx pipeline create פקודה.

!tfx pipeline create  --pipeline-path=kubeflow_runner.py --endpoint={ENDPOINT} \
--build-image
CLI
Usage: tfx pipeline create [OPTIONS]
Try 'tfx pipeline create --help' for help.

Error: no such option: --build-image

בעת יצירת צינור, Dockerfile יופק לבנות תדמית דוקרת. אל תשכח להוסיף אותו למערכת בקרת המקור (לדוגמה, git) יחד עם קבצי מקור אחרים.

עכשיו להתחיל בביצוע לרוץ עם הצינור החדש שנוצר באמצעות tfx run create פקודה.

tfx run create --pipeline-name={PIPELINE_NAME} --endpoint={ENDPOINT}
CLI
Creating a run for pipeline: my_pipeline
Detected Beam.
[WARNING] Default engine will be changed to "local" in the near future.
Use --engine flag if you intend to use a different orchestrator.
Pipeline "my_pipeline" does not exist.

לחלופין, אתה יכול גם להפעיל את הצינור בלוח המחוונים של KFP. ריצת הביצוע החדשה תופיע תחת ניסויים בלוח המחוונים של KFP. לחיצה על הניסוי תאפשר לך לעקוב אחר ההתקדמות ולדמיין את החפצים שנוצרו במהלך ריצת הביצוע.

עם זאת, אנו ממליצים לבקר במרכז השליטה של ​​KFP. אתה יכול לגשת ללוח המחוונים של KFP מתפריט Cloud AI Platform Pipelines ב-Google Cloud Console. לאחר שתבקר בלוח המחוונים, תוכל למצוא את הצינור ולגשת לשפע של מידע על הצינור. לדוגמה, אתה יכול למצוא הריצות שלך תחת תפריט הניסויים, וכאשר אתה פותח בריצת הביצוע שלך תחת ניסויים תוכל למצוא את כול החפצים שלך מהצנרת תחת תפריט חפצים.

אחד המקורות העיקריים לכישלון הוא בעיות הקשורות להרשאות. אנא ודא שלאשכול ה-KFP שלך יש הרשאות גישה לממשקי Google Cloud API. זה יכול להיות מוגדר בעת יצירת אשכול KFP ב GCP , או לראות במסמך פתרון בעיות ב- GCP .

שלב 5. הוסף רכיבים לאימות נתונים.

בשלב זה, תוכלו להוסיף רכיבים עבור אימות נתונים כולל StatisticsGen , SchemaGen , ו ExampleValidator . אם אתם מעוניינים אימות נתונים, ראה תחילת העבודה עם אימות נתונים Tensorflow .

לחץ פעמיים כדי לשנות ספרייה pipeline ולחץ פעמיים שוב כדי לפתוח pipeline.py . מצא ההערה 3 קווים אשר להוסיף StatisticsGen , SchemaGen , ו ExampleValidator בצנרת. (טיפ: חיפוש אחר הערות המכילות TODO(step 5): ). הקפד לשמור pipeline.py לאחר עריכתו.

כעת עליך לעדכן את הצינור הקיים עם הגדרת צינור שונה. השתמש tfx pipeline update הפקודה כדי לעדכן צינור שלך, ואחריו tfx run create פקודה ליצור בטווח ביצוע חדש של צינור המעודכן.

# Update the pipeline
!tfx pipeline update \
--pipeline-path=kubeflow_runner.py \
--endpoint={ENDPOINT}
# You can run the pipeline the same way.
!tfx run create --pipeline-name {PIPELINE_NAME} --endpoint={ENDPOINT}
CLI
Updating pipeline
Detected Beam.
[WARNING] Default engine will be changed to "local" in the near future.
Use --engine flag if you intend to use a different orchestrator.
beam runner not found in dsl.
CLI
Creating a run for pipeline: my_pipeline
Detected Beam.
[WARNING] Default engine will be changed to "local" in the near future.
Use --engine flag if you intend to use a different orchestrator.
Pipeline "my_pipeline" does not exist.

בדוק את תפוקות הצינור

בקר בלוח המחוונים של KFP כדי למצוא פלטי צינור בדף עבור הפעלת הצינור שלך. לחץ על הכרטיסייה ניסויים בצד שמאל, ואת כל הריצות בדף ניסויים. אתה אמור להיות מסוגל למצוא את הריצה האחרונה תחת השם של הצינור שלך.

שלב 6. הוסף רכיבים לאימון.

בשלב זה, תוכלו להוסיף רכיבים לאימונים אימות המודל כולל Transform , Trainer , Resolver , Evaluator , ו Pusher .

לחץ פעמיים כדי לפתוח pipeline.py . מצא ההערה 5 קווים אשר להוסיף Transform , Trainer , Resolver , Evaluator ו Pusher בצנרת. (טיפ: חיפוש אחר TODO(step 6): )

כפי שעשית בעבר, כעת עליך לעדכן את הצינור הקיים עם הגדרת הצינור ששונתה. ההנחיות זהות שלב 5. עדכון בצנרת באמצעות tfx pipeline update , וליצור בטווח ביצוע באמצעות tfx run create .

!tfx pipeline update \
--pipeline-path=kubeflow_runner.py \
--endpoint={ENDPOINT}
!tfx run create --pipeline-name {PIPELINE_NAME} --endpoint={ENDPOINT}
CLI
Updating pipeline
Detected Beam.
[WARNING] Default engine will be changed to "local" in the near future.
Use --engine flag if you intend to use a different orchestrator.
beam runner not found in dsl.
CLI
Creating a run for pipeline: my_pipeline
Detected Beam.
[WARNING] Default engine will be changed to "local" in the near future.
Use --engine flag if you intend to use a different orchestrator.
Pipeline "my_pipeline" does not exist.

כאשר ריצת ביצוע זו תסתיים בהצלחה, כעת יצרת והרצת את צינור ה-TFX הראשון שלך ב-AI Platform Pipelines!

שלב 7. (אופציונלי) נסה BigQueryExampleGen

BigQuery הוא ללא שרת, מדרגית, ואת מחסן נתוני ענן חסכוני. BigQuery יכול לשמש כמקור לדוגמאות הדרכה ב-TFX. בשלב זה, נוסיף BigQueryExampleGen בצנרת.

לחץ פעמיים כדי לפתוח pipeline.py . תגובה החוצה CsvExampleGen ו uncomment קו אשר יוצר מופע של BigQueryExampleGen . אתה גם צריך הערת query הטיעון של create_pipeline הפונקציה.

אנחנו צריכים לפרט איזה פרויקט GCP להשתמש עבור BigQuery, והדבר נעשה על ידי הגדרת --project ב beam_pipeline_args בעת יצירת צינור.

לחץ פעמיים כדי לפתוח configs.py . בטל הערה בהגדרת GOOGLE_CLOUD_REGION , BIG_QUERY_WITH_DIRECT_RUNNER_BEAM_PIPELINE_ARGS ו BIG_QUERY_QUERY . עליך להחליף את ערך האזור בקובץ זה בערכים הנכונים עבור פרויקט ה-GCP שלך.

שנה ספרייה רמה אחת למעלה. לחץ על שם הספרייה מעל רשימת הקבצים. שמו של המדריך הוא שמו של הצינור שהוא my_pipeline אם לא שינית.

לחץ פעמיים כדי לפתוח kubeflow_runner.py . שני טיעונים בטל הערה, query ואת beam_pipeline_args , עבור create_pipeline פונקציה.

כעת הצינור מוכן להשתמש ב-BigQuery כמקור לדוגמה. עדכן את הצינור כמו קודם וצור ריצת הפעלה חדשה כפי שעשינו בשלב 5 ו-6.

!tfx pipeline update \
--pipeline-path=kubeflow_runner.py \
--endpoint={ENDPOINT}
!tfx run create --pipeline-name {PIPELINE_NAME} --endpoint={ENDPOINT}
CLI
Updating pipeline
Detected Beam.
[WARNING] Default engine will be changed to "local" in the near future.
Use --engine flag if you intend to use a different orchestrator.
beam runner not found in dsl.
CLI
Creating a run for pipeline: my_pipeline
Detected Beam.
[WARNING] Default engine will be changed to "local" in the near future.
Use --engine flag if you intend to use a different orchestrator.
Pipeline "my_pipeline" does not exist.

שלב 8. (אופציונלי) נסה dataflow עם KFP

כמה TFX רכיבי משתמשת Apache Beam ליישם צינורות מקבילים נתונים, וזה אומר שאתה יכול להפיץ את עומסי העבודה עיבוד נתונים באמצעות Google Cloud dataflow . בשלב זה, נגדיר את מתזמר Kubeflow להשתמש ב-dataflow כחלק האחורי של עיבוד הנתונים עבור Apache Beam.

לחץ פעמיים pipeline למדריך שינוי, ולחץ לחיצה כפולה כדי לפתוח configs.py . ההגדרה בטל הערה של GOOGLE_CLOUD_REGION , ו DATAFLOW_BEAM_PIPELINE_ARGS .

שנה ספרייה רמה אחת למעלה. לחץ על שם הספרייה מעל רשימת הקבצים. שמו של המדריך הוא שמו של הצינור שהוא my_pipeline אם לא שינית.

לחץ פעמיים כדי לפתוח kubeflow_runner.py . בטל הערה beam_pipeline_args . (כן, ודא להגיב החוצה הנוכחי beam_pipeline_args שהוספת שלב 7.)

כעת הצינור מוכן לשימוש ב-Dataflow. עדכן את הצינור וצור ריצת ביצוע כפי שעשינו בשלב 5 ו-6.

!tfx pipeline update \
--pipeline-path=kubeflow_runner.py \
--endpoint={ENDPOINT}
!tfx run create --pipeline-name {PIPELINE_NAME} --endpoint={ENDPOINT}
CLI
Updating pipeline
Detected Beam.
[WARNING] Default engine will be changed to "local" in the near future.
Use --engine flag if you intend to use a different orchestrator.
beam runner not found in dsl.
CLI
Creating a run for pipeline: my_pipeline
Detected Beam.
[WARNING] Default engine will be changed to "local" in the near future.
Use --engine flag if you intend to use a different orchestrator.
Pipeline "my_pipeline" does not exist.

אתה יכול למצוא מקומות עבודה dataflow שלך dataflow ב Cloud Console .

שלב 9. (אופציונלי) נסה הדרכה בפלטפורמת ענן AI וחיזוי עם KFP

Interoperates TFX עם שירותי GCP כמה הצליח, כגון ענן AI פלטפורמה עבור הדרכה וחיזוי . אתה יכול להגדיר שלך Trainer רכיב כדי להשתמש ב- Cloud Platform AI הדרכה, שירות מנוהל להכשרת דגמי ML. יתר על כן, כאשר המודל שלך בנוי ומוכן להגשה, אתה יכול לדחוף את הדגם שלך ב- Cloud Platform AI חיזוי עבור משרתים. בשלב זה, נוכל להגדיר שלנו Trainer ו Pusher רכיב להשתמש בשירותים בפלטפורמת הענן AI.

לפני עריכת קבצים, ייתכן שיהיה ראשון כדי לאפשר הדרכת פלטפורמת AI & API לחיזוי.

לחץ פעמיים pipeline למדריך שינוי, ולחץ לחיצה כפולה כדי לפתוח configs.py . ההגדרה בטל הערה של GOOGLE_CLOUD_REGION , GCP_AI_PLATFORM_TRAINING_ARGS ו GCP_AI_PLATFORM_SERVING_ARGS . אנו נשתמש בתמונה מיכל שהותקן שלנו לאמן מודל ענן AI פלטפורמת הדרכה, אז אנחנו צריכים להגדיר masterConfig.imageUri ב GCP_AI_PLATFORM_TRAINING_ARGS לאותו ערך כמו CUSTOM_TFX_IMAGE לעיל.

המדריך שינוי ברמה אחת למעלה, ולחץ לחיצה כפולה כדי לפתוח kubeflow_runner.py . בטל הערה ai_platform_training_args ו ai_platform_serving_args .

עדכן את הצינור וצור ריצת ביצוע כפי שעשינו בשלב 5 ו-6.

!tfx pipeline update \
--pipeline-path=kubeflow_runner.py \
--endpoint={ENDPOINT}
!tfx run create --pipeline-name {PIPELINE_NAME} --endpoint={ENDPOINT}
CLI
Updating pipeline
Detected Beam.
[WARNING] Default engine will be changed to "local" in the near future.
Use --engine flag if you intend to use a different orchestrator.
beam runner not found in dsl.
CLI
Creating a run for pipeline: my_pipeline
Detected Beam.
[WARNING] Default engine will be changed to "local" in the near future.
Use --engine flag if you intend to use a different orchestrator.
Pipeline "my_pipeline" does not exist.

אתה יכול למצוא מקומות העבודה וההכשרה שלך קלאוד AI הפלטפורמה ג'ובס . אם הצינור שלך הושלם בהצלחה, אתה יכול למצוא את המודל ב- מודלים בפלטפורמת ענן AI .

שלב 10. הטמעת הנתונים שלך לצינור

יצרנו צינור למודל באמצעות מערך הנתונים של Chicago Taxi. עכשיו הגיע הזמן להכניס את הנתונים שלך לצינור.

ניתן לאחסן את הנתונים שלך בכל מקום שהצינור שלך יכול לגשת אליו, כולל GCS או BigQuery. תצטרך לשנות את הגדרת הצינור כדי לגשת לנתונים שלך.

  1. אם הנתונים שלך מאוחסן בקבצים, לשנות את DATA_PATH ב kubeflow_runner.py או local_runner.py ולהגדיר אותו למיקום של הקבצים שלך. אם הנתונים שלך מאוחסן BigQuery, לשנות BIG_QUERY_QUERY ב pipeline/configs.py לשאילתה כראוי עבור הנתונים שלך.
  2. הוספת תכונות models/features.py .
  3. שינוי models/preprocessing.py כדי להפוך נתונים קלט לאימונים .
  4. שינוי models/keras/model.py ו models/keras/constants.py כדי לתאר מודל ML שלך .
    • אתה יכול להשתמש גם במודל מבוסס אומד. שינוי RUN_FN מתמיד models.estimator.model.run_fn ב pipeline/configs.py .

אנא ראה מדריך רכיב מאמן עבור הקדמה יותר.

ניקיון

כדי לנקות את כל המשאבים Google Cloud בשימוש בפרויקט זה, אתה יכול למחוק את פרויקט Google Cloud השתמשת עבור הדרכה.

לחלופין, תוכל לנקות משאבים בודדים על ידי ביקור בכל קונסולות: