ভার্টেক্স এআই প্রশিক্ষণ এবং টিএফএক্স এবং ভার্টেক্স পাইপলাইনগুলির সাথে পরিবেশন করা

এই নোটবুক-ভিত্তিক টিউটোরিয়ালটি একটি TFX পাইপলাইন তৈরি এবং চালাবে যা Vertex AI প্রশিক্ষণ পরিষেবা ব্যবহার করে একটি ML মডেলকে প্রশিক্ষণ দেয় এবং পরিবেশনের জন্য Vertex AI-তে প্রকাশ করে।

এই নোটবুক TFX পাইপলাইন আমরা সালে নির্মিত উপর ভিত্তি করে তৈরি প্রান্তবিন্দু পাইপলাইন টিউটোরিয়াল এর জন্য সরল TFX পাইপলাইন । আপনি যদি এখনও সেই টিউটোরিয়ালটি না পড়ে থাকেন তবে এই নোটবুকটি নিয়ে এগিয়ে যাওয়ার আগে আপনার এটি পড়া উচিত।

আপনি AutoML ব্যবহার করে Vertex AI-তে মডেলদের প্রশিক্ষণ দিতে পারেন, অথবা কাস্টম প্রশিক্ষণ ব্যবহার করতে পারেন। কাস্টম প্রশিক্ষণে, আপনি আপনার প্রশিক্ষণের কাজগুলিকে শক্তিশালী করতে, বিতরণ করা প্রশিক্ষণ সক্ষম করতে, হাইপারপ্যারামিটার টিউনিং ব্যবহার করতে এবং GPU গুলির সাথে ত্বরান্বিত করতে বিভিন্ন ধরণের মেশিন নির্বাচন করতে পারেন।

আপনি ভার্টেক্স এআই মডেলগুলিতে প্রশিক্ষিত মডেল স্থাপন করে এবং একটি শেষ পয়েন্ট তৈরি করে ভবিষ্যদ্বাণী অনুরোধগুলিও পরিবেশন করতে পারেন।

এই টিউটোরিয়ালে, আমরা TFX পাইপলাইনে একটি মডেলকে প্রশিক্ষণের জন্য কাস্টম কাজের সাথে Vertex AI প্রশিক্ষণ ব্যবহার করব। আমরা Vertex AI ব্যবহার করে ভবিষ্যদ্বাণী অনুরোধ পরিবেশনের জন্য মডেলটি স্থাপন করব।

এই নোটবুক চালানো হবে দেয়ার উদ্দেশ্যে করা হচ্ছে গুগল Colab বা এআই প্ল্যাটফর্ম নোটবুক । আপনি যদি এর মধ্যে একটি ব্যবহার না করে থাকেন, তাহলে আপনি উপরের "Google Colab-এ চালান" বোতামে ক্লিক করতে পারেন।

সেট আপ করুন

সম্পন্ন করা, তাহলে প্রান্তবিন্দু পাইপলাইন টিউটোরিয়াল এর জন্য সরল TFX পাইপলাইন , আপনি একটি কাজ GCP প্রকল্প এবং একটি GCS বালতি থাকবে এবং যে সমস্ত আমরা এই টিউটোরিয়ালের জন্য প্রয়োজন হয়। অনুগ্রহ করে প্রথমে প্রাথমিক টিউটোরিয়ালটি পড়ুন যদি আপনি এটি মিস করেন।

পাইথন প্যাকেজ ইনস্টল করুন

আমরা ML পাইপলাইন লেখকের কাছে TFX এবং KFP সহ প্রয়োজনীয় পাইথন প্যাকেজ ইনস্টল করব এবং Vertex পাইপলাইনে চাকরি জমা দেব।

# Use the latest version of pip.
pip install --upgrade pip
pip install --upgrade "tfx[kfp]<2"

আপনি কি রানটাইম রিস্টার্ট করেছেন?

আপনি যদি Google Colab ব্যবহার করেন, প্রথমবার যখন আপনি উপরের সেলটি চালান, তাহলে আপনাকে অবশ্যই উপরে "রিস্টার্ট RUNTIME" বোতামে ক্লিক করে বা "রানটাইম > রানটাইম রিস্টার্ট..." মেনু ব্যবহার করে রানটাইম রিস্টার্ট করতে হবে। Colab যেভাবে প্যাকেজগুলি লোড করে তার কারণেই এটি হয়েছে৷

আপনি Colab-এ না থাকলে, নিম্নলিখিত সেল দিয়ে রানটাইম রিস্টার্ট করতে পারেন।

# docs_infra: no_execute
import sys
if not 'google.colab' in sys.modules:
  # Automatically restart kernel after installs
  import IPython
  app = IPython.Application.instance()
  app.kernel.do_shutdown(True)

এই নোটবুকের জন্য গুগলে লগ ইন করুন

আপনি যদি Colab-এ এই নোটবুকটি চালান, তাহলে আপনার ব্যবহারকারীর অ্যাকাউন্ট দিয়ে প্রমাণীকরণ করুন:

import sys
if 'google.colab' in sys.modules:
  from google.colab import auth
  auth.authenticate_user()

আপনি পরবর্তী অধ্যায় চলমান, চলমান দ্বারা ইতিপূর্বে এআই প্ল্যাটফর্ম নোটবুক, Google মেঘ সহ প্রমাণীকরণ হন

gcloud auth login

টার্মিনাল উইন্ডোতে (যা আপনার কাছে সেই ফাইলে মাধ্যমে খুলতে পারে> মেনুতে নতুন)। আপনি শুধুমাত্র নোটবুক উদাহরণ প্রতি একবার এটি করতে হবে.

প্যাকেজ সংস্করণ পরীক্ষা করুন.

import tensorflow as tf
print('TensorFlow version: {}'.format(tf.__version__))
from tfx import v1 as tfx
print('TFX version: {}'.format(tfx.__version__))
import kfp
print('KFP version: {}'.format(kfp.__version__))
TensorFlow version: 2.6.2
TFX version: 1.4.0
KFP version: 1.8.1

ভেরিয়েবল সেট আপ করুন

আমরা নীচের পাইপলাইনগুলি কাস্টমাইজ করতে ব্যবহৃত কিছু ভেরিয়েবল সেট আপ করব। নিম্নলিখিত তথ্য প্রয়োজন:

এটা চালানোর আগে নিচের কক্ষে প্রয়োজনীয় মান সন্নিবেশ করান।

GOOGLE_CLOUD_PROJECT = ''     # <--- ENTER THIS
GOOGLE_CLOUD_REGION = ''      # <--- ENTER THIS
GCS_BUCKET_NAME = ''          # <--- ENTER THIS

if not (GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_REGION and GCS_BUCKET_NAME):
    from absl import logging
    logging.error('Please set all required parameters.')
ERROR:absl:Please set all required parameters.

সেট gcloud আপনার প্রকল্পের ব্যবহার করতে।

gcloud config set project {GOOGLE_CLOUD_PROJECT}
ERROR: (gcloud.config.set) argument VALUE: Must be specified.
Usage: gcloud config set SECTION/PROPERTY VALUE [optional flags]
  optional flags may be  --help | --installation

For detailed information on this command and its flags, run:
  gcloud config set --help
PIPELINE_NAME = 'penguin-vertex-training'

# Path to various pipeline artifact.
PIPELINE_ROOT = 'gs://{}/pipeline_root/{}'.format(GCS_BUCKET_NAME, PIPELINE_NAME)

# Paths for users' Python module.
MODULE_ROOT = 'gs://{}/pipeline_module/{}'.format(GCS_BUCKET_NAME, PIPELINE_NAME)

# Paths for users' data.
DATA_ROOT = 'gs://{}/data/{}'.format(GCS_BUCKET_NAME, PIPELINE_NAME)

# Name of Vertex AI Endpoint.
ENDPOINT_NAME = 'prediction-' + PIPELINE_NAME

print('PIPELINE_ROOT: {}'.format(PIPELINE_ROOT))
PIPELINE_ROOT: gs:///pipeline_root/penguin-vertex-training

উদাহরণ ডেটা প্রস্তুত করুন

আমরা একই ব্যবহার করবে পামার পেঙ্গুইনদের ডেটা সেটটি যেমন সরল TFX পাইপলাইন টিউটোরিয়াল

এই ডেটাসেটে চারটি সংখ্যাসূচক বৈশিষ্ট্য রয়েছে যা ইতিমধ্যেই পরিসীমা [0,1] থাকার জন্য স্বাভাবিক করা হয়েছে। আমরা একটি শ্রেণীবিভাগ মডেল যা অনুমান গড়ে তুলবে species পেঙ্গুইনদের করুন।

আমাদের ডেটাসেটের নিজস্ব কপি তৈরি করতে হবে। যেহেতু TFX ExampleGen একটি ডিরেক্টরি থেকে ইনপুট পড়ে, আমাদের একটি ডিরেক্টরি তৈরি করতে হবে এবং GCS-এ ডেটাসেট কপি করতে হবে।

gsutil cp gs://download.tensorflow.org/data/palmer_penguins/penguins_processed.csv {DATA_ROOT}/
InvalidUrlError: Cloud URL scheme should be followed by colon and two slashes: "://". Found: "gs:///data/penguin-vertex-training/".

CSV ফাইলটি দ্রুত দেখে নিন।

gsutil cat {DATA_ROOT}/penguins_processed.csv | head
InvalidUrlError: Cloud URL scheme should be followed by colon and two slashes: "://". Found: "gs:///data/penguin-vertex-training/penguins_processed.csv".

একটি পাইপলাইন তৈরি করুন

আমাদের পাইপলাইন খুব পাইপলাইন আমরা তৈরি অনুরূপ হতে হবে প্রান্তবিন্দু পাইপলাইন টিউটোরিয়াল এর জন্য সরল TFX পাইপলাইন । পাইপলাইনে তিনটি উপাদান থাকবে, CsvExampleGen, Trainer এবং Pusher। তবে আমরা একটি বিশেষ প্রশিক্ষক এবং পুশার উপাদান ব্যবহার করব। প্রশিক্ষক কম্পোনেন্ট ট্রেনিং ওয়ার্কলোডগুলিকে Vertex AI-তে নিয়ে যাবে এবং Pusher কম্পোনেন্ট প্রশিক্ষিত ML মডেলটিকে ফাইল সিস্টেমের পরিবর্তে Vertex AI-তে প্রকাশ করবে।

TFX একটি বিশেষ প্রদান করে Trainer প্রান্তবিন্দু এআই প্রশিক্ষণ সেবার প্রশিক্ষণ কাজ জমা দিন। আমরা যা করতে হবে ব্যবহার Trainer এক্সটেনশন মডিউল পরিবর্তে মান মধ্যে Trainer কিছু প্রয়োজনীয় GCP পরামিতি সহ অংশটি।

এই টিউটোরিয়ালে, আমরা প্রথমে সিপিইউ ব্যবহার করে এবং তারপর একটি জিপিইউ ব্যবহার করে Vertex AI প্রশিক্ষণের কাজ চালাব।

TFX একটি বিশেষ প্রদান করে Pusher প্রান্তবিন্দু এআই মডেলের মডেল আপলোড করতে। Pusher প্রান্তবিন্দু এআই এন্ডপয়েন্ট রিসোর্স খুব তৈরি অনলাইন perdictions পরিবেশন করা হবে। দেখুন প্রান্তবিন্দু এআই ডকুমেন্টেশন অনলাইন প্রান্তবিন্দু এআই দ্বারা উপলব্ধ ভবিষ্যৎবাণী সম্পর্কে আরো জানতে।

মডেল কোড লিখুন।

মডেল নিজেই প্রায় মডেল অনুরূপ সরল TFX পাইপলাইন টিউটোরিয়াল

আমরা যোগ হবে _get_distribution_strategy() ফাংশন যা সৃষ্টি TensorFlow বন্টন কৌশল এবং এটি ব্যবহার করা হয় run_fn MirroredStrategy ব্যবহার করতে যদি জিপিইউ পাওয়া যায়।

_trainer_module_file = 'penguin_trainer.py'
%%writefile {_trainer_module_file}

# Copied from https://www.tensorflow.org/tfx/tutorials/tfx/penguin_simple and
# slightly modified run_fn() to add distribution_strategy.

from typing import List
from absl import logging
import tensorflow as tf
from tensorflow import keras
from tensorflow_metadata.proto.v0 import schema_pb2
from tensorflow_transform.tf_metadata import schema_utils

from tfx import v1 as tfx
from tfx_bsl.public import tfxio

_FEATURE_KEYS = [
    'culmen_length_mm', 'culmen_depth_mm', 'flipper_length_mm', 'body_mass_g'
]
_LABEL_KEY = 'species'

_TRAIN_BATCH_SIZE = 20
_EVAL_BATCH_SIZE = 10

# Since we're not generating or creating a schema, we will instead create
# a feature spec.  Since there are a fairly small number of features this is
# manageable for this dataset.
_FEATURE_SPEC = {
    **{
        feature: tf.io.FixedLenFeature(shape=[1], dtype=tf.float32)
        for feature in _FEATURE_KEYS
    }, _LABEL_KEY: tf.io.FixedLenFeature(shape=[1], dtype=tf.int64)
}


def _input_fn(file_pattern: List[str],
              data_accessor: tfx.components.DataAccessor,
              schema: schema_pb2.Schema,
              batch_size: int) -> tf.data.Dataset:
  """Generates features and label for training.

  Args:
    file_pattern: List of paths or patterns of input tfrecord files.
    data_accessor: DataAccessor for converting input to RecordBatch.
    schema: schema of the input data.
    batch_size: representing the number of consecutive elements of returned
      dataset to combine in a single batch

  Returns:
    A dataset that contains (features, indices) tuple where features is a
      dictionary of Tensors, and indices is a single Tensor of label indices.
  """
  return data_accessor.tf_dataset_factory(
      file_pattern,
      tfxio.TensorFlowDatasetOptions(
          batch_size=batch_size, label_key=_LABEL_KEY),
      schema=schema).repeat()


def _make_keras_model() -> tf.keras.Model:
  """Creates a DNN Keras model for classifying penguin data.

  Returns:
    A Keras Model.
  """
  # The model below is built with Functional API, please refer to
  # https://www.tensorflow.org/guide/keras/overview for all API options.
  inputs = [keras.layers.Input(shape=(1,), name=f) for f in _FEATURE_KEYS]
  d = keras.layers.concatenate(inputs)
  for _ in range(2):
    d = keras.layers.Dense(8, activation='relu')(d)
  outputs = keras.layers.Dense(3)(d)

  model = keras.Model(inputs=inputs, outputs=outputs)
  model.compile(
      optimizer=keras.optimizers.Adam(1e-2),
      loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
      metrics=[keras.metrics.SparseCategoricalAccuracy()])

  model.summary(print_fn=logging.info)
  return model


# NEW: Read `use_gpu` from the custom_config of the Trainer.
#      if it uses GPU, enable MirroredStrategy.
def _get_distribution_strategy(fn_args: tfx.components.FnArgs):
  if fn_args.custom_config.get('use_gpu', False):
    logging.info('Using MirroredStrategy with one GPU.')
    return tf.distribute.MirroredStrategy(devices=['device:GPU:0'])
  return None


# TFX Trainer will call this function.
def run_fn(fn_args: tfx.components.FnArgs):
  """Train the model based on given args.

  Args:
    fn_args: Holds args used to train the model as name/value pairs.
  """

  # This schema is usually either an output of SchemaGen or a manually-curated
  # version provided by pipeline author. A schema can also derived from TFT
  # graph if a Transform component is used. In the case when either is missing,
  # `schema_from_feature_spec` could be used to generate schema from very simple
  # feature_spec, but the schema returned would be very primitive.
  schema = schema_utils.schema_from_feature_spec(_FEATURE_SPEC)

  train_dataset = _input_fn(
      fn_args.train_files,
      fn_args.data_accessor,
      schema,
      batch_size=_TRAIN_BATCH_SIZE)
  eval_dataset = _input_fn(
      fn_args.eval_files,
      fn_args.data_accessor,
      schema,
      batch_size=_EVAL_BATCH_SIZE)

  # NEW: If we have a distribution strategy, build a model in a strategy scope.
  strategy = _get_distribution_strategy(fn_args)
  if strategy is None:
    model = _make_keras_model()
  else:
    with strategy.scope():
      model = _make_keras_model()

  model.fit(
      train_dataset,
      steps_per_epoch=fn_args.train_steps,
      validation_data=eval_dataset,
      validation_steps=fn_args.eval_steps)

  # The result of the training should be saved in `fn_args.serving_model_dir`
  # directory.
  model.save(fn_args.serving_model_dir, save_format='tf')
Writing penguin_trainer.py

মডিউল ফাইলটি GCS-এ অনুলিপি করুন যা পাইপলাইনের উপাদানগুলি থেকে অ্যাক্সেস করা যেতে পারে।

অন্যথায়, আপনি মডিউল ফাইল সহ একটি ধারক চিত্র তৈরি করতে এবং পাইপলাইন এবং এআই প্ল্যাটফর্ম প্রশিক্ষণের কাজগুলি চালানোর জন্য চিত্রটি ব্যবহার করতে চাইতে পারেন।

gsutil cp {_trainer_module_file} {MODULE_ROOT}/
InvalidUrlError: Cloud URL scheme should be followed by colon and two slashes: "://". Found: "gs:///pipeline_module/penguin-vertex-training/".

পাইপলাইনের সংজ্ঞা লিখ

আমরা একটি TFX পাইপলাইন তৈরি করার জন্য একটি ফাংশন সংজ্ঞায়িত করব। এটা হিসাবে একই তিনটি উপাদান রয়েছে সরল TFX পাইপলাইন টিউটোরিয়াল , কিন্তু আমরা একটি ব্যবহার Trainer এবং Pusher GCP এক্সটেনশন মডিউলে অংশটি।

tfx.extensions.google_cloud_ai_platform.Trainer একটি নিয়মিত মত আচরণ Trainer , কিন্তু এটা শুধু ক্লাউডে মডেল প্রশিক্ষণের জন্য গণনার চলে আসে। এটি Vertex AI প্রশিক্ষণ পরিষেবাতে একটি কাস্টম কাজ চালু করে এবং অর্কেস্ট্রেশন সিস্টেমের প্রশিক্ষক উপাদানটি Vertex AI প্রশিক্ষণের কাজ সম্পূর্ণ না হওয়া পর্যন্ত অপেক্ষা করবে।

tfx.extensions.google_cloud_ai_platform.Pusher প্রশিক্ষিত মডেল ব্যবহার করে একটি প্রান্তবিন্দু এআই মডেল এবং একটি প্রান্তবিন্দু এআই এন্ডপয়েন্ট তৈরি করে।

def _create_pipeline(pipeline_name: str, pipeline_root: str, data_root: str,
                     module_file: str, endpoint_name: str, project_id: str,
                     region: str, use_gpu: bool) -> tfx.dsl.Pipeline:
  """Implements the penguin pipeline with TFX."""
  # Brings data into the pipeline or otherwise joins/converts training data.
  example_gen = tfx.components.CsvExampleGen(input_base=data_root)

  # NEW: Configuration for Vertex AI Training.
  # This dictionary will be passed as `CustomJobSpec`.
  vertex_job_spec = {
      'project': project_id,
      'worker_pool_specs': [{
          'machine_spec': {
              'machine_type': 'n1-standard-4',
          },
          'replica_count': 1,
          'container_spec': {
              'image_uri': 'gcr.io/tfx-oss-public/tfx:{}'.format(tfx.__version__),
          },
      }],
  }
  if use_gpu:
    # See https://cloud.google.com/vertex-ai/docs/reference/rest/v1/MachineSpec#acceleratortype
    # for available machine types.
    vertex_job_spec['worker_pool_specs'][0]['machine_spec'].update({
        'accelerator_type': 'NVIDIA_TESLA_K80',
        'accelerator_count': 1
    })

  # Trains a model using Vertex AI Training.
  # NEW: We need to specify a Trainer for GCP with related configs.
  trainer = tfx.extensions.google_cloud_ai_platform.Trainer(
      module_file=module_file,
      examples=example_gen.outputs['examples'],
      train_args=tfx.proto.TrainArgs(num_steps=100),
      eval_args=tfx.proto.EvalArgs(num_steps=5),
      custom_config={
          tfx.extensions.google_cloud_ai_platform.ENABLE_UCAIP_KEY:
              True,
          tfx.extensions.google_cloud_ai_platform.UCAIP_REGION_KEY:
              region,
          tfx.extensions.google_cloud_ai_platform.TRAINING_ARGS_KEY:
              vertex_job_spec,
          'use_gpu':
              use_gpu,
      })

  # NEW: Configuration for pusher.
  vertex_serving_spec = {
      'project_id': project_id,
      'endpoint_name': endpoint_name,
      # Remaining argument is passed to aiplatform.Model.deploy()
      # See https://cloud.google.com/vertex-ai/docs/predictions/deploy-model-api#deploy_the_model
      # for the detail.
      #
      # Machine type is the compute resource to serve prediction requests.
      # See https://cloud.google.com/vertex-ai/docs/predictions/configure-compute#machine-types
      # for available machine types and acccerators.
      'machine_type': 'n1-standard-4',
  }

  # Vertex AI provides pre-built containers with various configurations for
  # serving.
  # See https://cloud.google.com/vertex-ai/docs/predictions/pre-built-containers
  # for available container images.
  serving_image = 'us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-6:latest'
  if use_gpu:
    vertex_serving_spec.update({
        'accelerator_type': 'NVIDIA_TESLA_K80',
        'accelerator_count': 1
    })
    serving_image = 'us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-6:latest'

  # NEW: Pushes the model to Vertex AI.
  pusher = tfx.extensions.google_cloud_ai_platform.Pusher(
      model=trainer.outputs['model'],
      custom_config={
          tfx.extensions.google_cloud_ai_platform.ENABLE_VERTEX_KEY:
              True,
          tfx.extensions.google_cloud_ai_platform.VERTEX_REGION_KEY:
              region,
          tfx.extensions.google_cloud_ai_platform.VERTEX_CONTAINER_IMAGE_URI_KEY:
              serving_image,
          tfx.extensions.google_cloud_ai_platform.SERVING_ARGS_KEY:
            vertex_serving_spec,
      })

  components = [
      example_gen,
      trainer,
      pusher,
  ]

  return tfx.dsl.Pipeline(
      pipeline_name=pipeline_name,
      pipeline_root=pipeline_root,
      components=components)

ভার্টেক্স পাইপলাইনে পাইপলাইন চালান।

আমরা যেমন করেছিল পাইপলাইন চালানোর জন্য প্রান্তবিন্দু পাইপলাইন ব্যবহার করবে প্রান্তবিন্দু পাইপলাইন টিউটোরিয়াল এর জন্য সরল TFX পাইপলাইন

import os

PIPELINE_DEFINITION_FILE = PIPELINE_NAME + '_pipeline.json'

runner = tfx.orchestration.experimental.KubeflowV2DagRunner(
    config=tfx.orchestration.experimental.KubeflowV2DagRunnerConfig(),
    output_filename=PIPELINE_DEFINITION_FILE)
_ = runner.run(
    _create_pipeline(
        pipeline_name=PIPELINE_NAME,
        pipeline_root=PIPELINE_ROOT,
        data_root=DATA_ROOT,
        module_file=os.path.join(MODULE_ROOT, _trainer_module_file),
        endpoint_name=ENDPOINT_NAME,
        project_id=GOOGLE_CLOUD_PROJECT,
        region=GOOGLE_CLOUD_REGION,
        # We will use CPUs only for now.
        use_gpu=False))

উত্পন্ন সংজ্ঞা ফাইলে Google মেঘ aiplatform ক্লায়েন্ট ব্যবহার জমা করা যেতে পারে google-cloud-aiplatform প্যাকেজ।

# docs_infra: no_execute
from google.cloud import aiplatform
from google.cloud.aiplatform import pipeline_jobs

aiplatform.init(project=GOOGLE_CLOUD_PROJECT, location=GOOGLE_CLOUD_REGION)

job = pipeline_jobs.PipelineJob(template_path=PIPELINE_DEFINITION_FILE,
                                display_name=PIPELINE_NAME)
job.run(sync=False)

এখন আপনি পরিদর্শন করতে পারেন 'প্রান্তবিন্দু এআই> পাইপলাইন' মধ্যে Google Cloud Console অগ্রগতি দেখতে।

একটি ভবিষ্যদ্বাণী অনুরোধ সঙ্গে পরীক্ষা

একবার পাইপলাইন সম্পূর্ণ হলে, আপনি 'প্রান্তবিন্দু এআই> এন্ডপয়েন্ট' থেকে এন্ড পয়েন্ট এক সময়ে একটি মোতায়েন মডেল পাবেন। নতুন এন্ডপয়েন্টে ভবিষ্যদ্বাণী অনুরোধ পাঠাতে আমাদের এন্ডপয়েন্টের আইডি জানতে হবে। এই আমরা উপরে লেখা শেষবিন্দু নাম থেকে ভিন্ন। আপনি আইডি জানতে পারেন এন্ডপয়েন্ট পৃষ্ঠা মধ্যে Google Cloud Console , এটি একটি খুব দীর্ঘ সংখ্যা মত দেখায়।

এটি চালানোর আগে নীচে ENDPOINT_ID সেট করুন৷

ENDPOINT_ID=''     # <--- ENTER THIS
if not ENDPOINT_ID:
    from absl import logging
    logging.error('Please set the endpoint id.')
ERROR:absl:Please set the endpoint id.

আমরা শেষ পয়েন্টে একটি অনুরোধ পাঠাতে একই aipplatform ক্লায়েন্ট ব্যবহার করি। আমরা পেঙ্গুইন প্রজাতির শ্রেণীবিভাগের জন্য একটি ভবিষ্যদ্বাণী অনুরোধ পাঠাব। ইনপুট হল চারটি বৈশিষ্ট্য যা আমরা ব্যবহার করেছি এবং মডেলটি তিনটি মান ফিরিয়ে দেবে, কারণ আমাদের মডেল প্রতিটি প্রজাতির জন্য একটি মান আউটপুট করে।

উদাহরণস্বরূপ, নিম্নলিখিত নির্দিষ্ট উদাহরণের সূচক '2'-এ সবচেয়ে বড় মান রয়েছে এবং '2' প্রিন্ট করবে।

# docs_infra: no_execute
import numpy as np

# The AI Platform services require regional API endpoints.
client_options = {
    'api_endpoint': GOOGLE_CLOUD_REGION + '-aiplatform.googleapis.com'
    }
# Initialize client that will be used to create and send requests.
client = aiplatform.gapic.PredictionServiceClient(client_options=client_options)

# Set data values for the prediction request.
# Our model expects 4 feature inputs and produces 3 output values for each
# species. Note that the output is logit value rather than probabilities.
# See the model code to understand input / output structure.
instances = [{
    'culmen_length_mm':[0.71],
    'culmen_depth_mm':[0.38],
    'flipper_length_mm':[0.98],
    'body_mass_g': [0.78],
}]

endpoint = client.endpoint_path(
    project=GOOGLE_CLOUD_PROJECT,
    location=GOOGLE_CLOUD_REGION,
    endpoint=ENDPOINT_ID,
)
# Send a prediction request and get response.
response = client.predict(endpoint=endpoint, instances=instances)

# Uses argmax to find the index of the maximum value.
print('species:', np.argmax(response.predictions[0]))

অনলাইন ভবিষ্যদ্বাণী সম্পর্কে বিস্তারিত তথ্যের জন্য, অনুগ্রহ করে পরিদর্শন এন্ডপয়েন্ট পৃষ্ঠা মধ্যে Google Cloud Console । আপনি নমুনা অনুরোধ এবং আরও সম্পদের লিঙ্ক পাঠানোর জন্য একটি গাইড খুঁজে পেতে পারেন।

একটি GPU ব্যবহার করে পাইপলাইন চালান

ভার্টেক্স এআই জিপিইউ-এর জন্য সমর্থন সহ বিভিন্ন ধরনের মেশিন ব্যবহার করে প্রশিক্ষণ সমর্থন করে। দেখুন মেশিন বৈশিষ্ট রেফারেন্স উপলব্ধ অপশন জন্য।

আমরা ইতিমধ্যে GPU প্রশিক্ষণ সমর্থন করার জন্য আমাদের পাইপলাইন সংজ্ঞায়িত. আমরা যা করতে হবে সেটিং use_gpu সত্যতে পতাকা। তারপর একটি পাইপলাইন একটি মেশিন এক NVIDIA_TESLA_K80 এবং আমাদের মডেল প্রশিক্ষণ কোড সহ ব্যবহার করবে বৈশিষ্ট সঙ্গে তৈরি করা হবে tf.distribute.MirroredStrategy

মনে রাখবেন যে, use_gpu পতাকা প্রান্তবিন্দু বা TFX API- এর একটি অংশ নয়। এটি শুধুমাত্র এই টিউটোরিয়ালে প্রশিক্ষণ কোড নিয়ন্ত্রণ করতে ব্যবহৃত হয়।

# docs_infra: no_execute
runner.run(
    _create_pipeline(
        pipeline_name=PIPELINE_NAME,
        pipeline_root=PIPELINE_ROOT,
        data_root=DATA_ROOT,
        module_file=os.path.join(MODULE_ROOT, _trainer_module_file),
        endpoint_name=ENDPOINT_NAME,
        project_id=GOOGLE_CLOUD_PROJECT,
        region=GOOGLE_CLOUD_REGION,
        # Updated: Use GPUs. We will use a NVIDIA_TESLA_K80 and 
        # the model code will use tf.distribute.MirroredStrategy.
        use_gpu=True))

job = pipeline_jobs.PipelineJob(template_path=PIPELINE_DEFINITION_FILE,
                                display_name=PIPELINE_NAME)
job.run(sync=False)

এখন আপনি পরিদর্শন করতে পারেন 'প্রান্তবিন্দু এআই> পাইপলাইন' মধ্যে Google Cloud Console অগ্রগতি দেখতে।

পরিষ্কার আপ

আপনি এই টিউটোরিয়ালে একটি ভার্টেক্স এআই মডেল এবং এন্ডপয়েন্ট তৈরি করেছেন। এ গিয়ে কোন অবাঞ্ছিত চার্জ এড়াতে এই সম্পদ মুছে দিন দয়া করে এন্ডপয়েন্ট এবং শেষবিন্দু থেকে মডেল undeploying প্রথম। তারপর আপনি শেষ পয়েন্ট এবং মডেল আলাদাভাবে মুছে ফেলতে পারেন।