您可以將 GPU 加速器連接至 Dataproc Serverless 批次工作負載,以便達成以下目標:
加快處理大規模資料分析工作負載的速度。
使用 GPU 機器學習程式庫,加快大型資料集的模型訓練速度。
執行進階資料分析,例如影片或自然語言處理。
所有支援的 Dataproc Serverless Spark 執行階段都會將 Spark RAPIDS 程式庫新增至每個工作負載節點。Dataproc Serverless for Spark 執行階段版本 1.1 也將 XGBoost 程式庫新增至工作負載節點。這些程式庫提供強大的資料轉換和機器學習工具,可用於 GPU 加速工作負載。
GPU 優點
以下是使用 GPU 搭配 Dataproc Serverless Spark 工作負載的部分優點:
效能提升:GPU 加速功能可大幅提升 Spark 工作負載效能,特別是運算密集型工作,例如機器和深度學習、圖表處理和複雜分析。
加快模型訓練速度:對於機器學習工作而言,附加 GPU 可大幅縮短訓練模型所需的時間,讓數據資料學家和工程師能夠快速疊代和實驗。
可擴充性:客戶可以為節點新增更多 GPU 節點或更強大的 GPU,以處理日益複雜的處理需求。
成本效益:雖然 GPU 需要初始投資,但由於可縮短處理時間並更有效率地運用資源,因此您可以隨著時間的推移節省成本。
強化資料分析:GPU 加速功能可讓您在大型資料集上執行進階分析,例如圖片和影片分析以及自然語言處理。
改善產品:處理速度更快,可加快決策速度,並提升應用程式的回應速度。
限制和注意事項
您可以將 NVIDIA A100 或 NVIDIA L4 GPU 連結至 Dataproc 無伺服器批次工作負載。A100 和 L4 加速器的使用情形取決於 Compute Engine GPU 區域可用性。
使用 Dataproc Serverless Spark 執行階段版本 1.x 時,只有 Dataproc Serverless GPU 加速工作負載才會提供 XGBoost 程式庫。
使用 XGBoost 的 Dataproc 無伺服器 GPU 加速批次會使用增加的 Compute Engine 配額。舉例來說,如要執行使用 NVIDIA L4 GPU 的無伺服器批次工作負載,您必須分配 NVIDIA_L4_GPUS 配額。
啟用加速器的工作與
constraints/compute.requireShieldedVm
機構政策不相容。如果貴機構強制執行這項政策,啟用加速器的工作就無法順利執行。使用 RAPIDS GPU 加速功能時,如果使用的是 支援的 Dataproc Serverless 執行階段 (版本為
2.2
之前),則必須將預設字元集設為 UTF-8。詳情請參閱「使用 GPU 加速器建立無伺服器批次工作負載」一文。
定價
如要瞭解加速器定價資訊,請參閱「Dataproc Serverless 定價」一文。
事前準備
建立附加 GPU 加速器的無伺服器批次工作負載前,請先執行下列操作:
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Dataproc, Compute Engine, and Cloud Storage APIs.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Dataproc, Compute Engine, and Cloud Storage APIs.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
- In the Google Cloud console, go to the Cloud Storage Buckets page.
- Click Create.
- On the Create a bucket page, enter your bucket information. To go to the next
step, click Continue.
-
In the Get started section, do the following:
- Enter a globally unique name that meets the bucket naming requirements.
- To add a
bucket label,
expand the Labels section ( ),
click add_box
Add label, and specify a
key
and avalue
for your label.
-
In the Choose where to store your data section, do the following:
- Select a Location type.
- Choose a location where your bucket's data is permanently stored from the Location type drop-down menu.
- If you select the dual-region location type, you can also choose to enable turbo replication by using the relevant checkbox.
- To set up cross-bucket replication, select
Add cross-bucket replication via Storage Transfer Service and
follow these steps:
Set up cross-bucket replication
- In the Bucket menu, select a bucket.
In the Replication settings section, click Configure to configure settings for the replication job.
The Configure cross-bucket replication pane appears.
- To filter objects to replicate by object name prefix, enter a prefix that you want to include or exclude objects from, then click Add a prefix.
- To set a storage class for the replicated objects, select a storage class from the Storage class menu. If you skip this step, the replicated objects will use the destination bucket's storage class by default.
- Click Done.
-
In the Choose how to store your data section, do the following:
- Select a default storage class for the bucket or Autoclass for automatic storage class management of your bucket's data.
- To enable hierarchical namespace, in the Optimize storage for data-intensive workloads section, select Enable hierarchical namespace on this bucket.
- In the Choose how to control access to objects section, select whether or not your bucket enforces public access prevention, and select an access control method for your bucket's objects.
-
In the Choose how to protect object data section, do the
following:
- Select any of the options under Data protection that you
want to set for your bucket.
- To enable soft delete, click the Soft delete policy (For data recovery) checkbox, and specify the number of days you want to retain objects after deletion.
- To set Object Versioning, click the Object versioning (For version control) checkbox, and specify the maximum number of versions per object and the number of days after which the noncurrent versions expire.
- To enable the retention policy on objects and buckets, click the Retention (For compliance) checkbox, and then do the following:
- To enable Object Retention Lock, click the Enable object retention checkbox.
- To enable Bucket Lock, click the Set bucket retention policy checkbox, and choose a unit of time and a length of time for your retention period.
- To choose how your object data will be encrypted, expand the Data encryption section (Data encryption method. ), and select a
- Select any of the options under Data protection that you
want to set for your bucket.
-
In the Get started section, do the following:
- Click Create.
按一下「Expand me」,然後使用文字或程式碼編輯器,在本機電腦上建立並儲存清單中的 PySpark 程式碼至
test-py-spark-gpu.py
檔案。#!/usr/bin/env python """S8s Accelerators Example.""" import subprocess from typing import Any from pyspark.sql import SparkSession from pyspark.sql.functions import col from pyspark.sql.types import IntegerType from pyspark.sql.types import StructField from pyspark.sql.types import StructType spark = SparkSession.builder.appName("joindemo").getOrCreate() def get_num_gpus(_: Any) -> int: """Returns the number of GPUs.""" p_nvidia_smi = subprocess.Popen( ["nvidia-smi", "-L"], stdin=None, stdout=subprocess.PIPE ) p_wc = subprocess.Popen( ["wc", "-l"], stdin=p_nvidia_smi.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, ) [out, _] = p_wc.communicate() return int(out) num_workers = 5 result = ( spark.sparkContext.range(0, num_workers, 1, num_workers) .map(get_num_gpus) .collect() ) num_gpus = sum(result) print(f"Total accelerators: {num_gpus}") # Run the join example schema = StructType([StructField("value", IntegerType(), True)]) df = ( spark.sparkContext.parallelize(range(1, 10000001), 6) .map(lambda x: (x,)) .toDF(schema) ) df2 = ( spark.sparkContext.parallelize(range(1, 10000001), 6) .map(lambda x: (x,)) .toDF(schema) ) joined_df = ( df.select(col("value").alias("a")) .join(df2.select(col("value").alias("b")), col("a") == col("b")) .explain() )
在本機機器上使用 gcloud CLI,提交含有五個工作站的 Dataproc Serverless 無伺服器批次工作,每個工作站都使用 L4 GPU 加速:
gcloud dataproc batches submit pyspark test-py-spark-gpu.py \ --project=PROJECT_ID \ --region=REGION \ --deps-bucket=BUCKET_NAME \ --version=1.1 \ --properties=spark.dataproc.executor.compute.tier=premium,spark.dataproc.executor.disk.tier=premium,spark.dataproc.executor.resource.accelerator.type=l4,spark.executor.instances=5,spark.dataproc.driverEnv.LANG=C.UTF-8,spark.executorEnv.LANG=C.UTF-8,spark.shuffle.manager=com.nvidia.spark.rapids.RapidsShuffleManager
- PROJECT_ID:您的 Google Cloud 專案 ID。
- REGION:可用來執行工作負載的 Compute Engine 區域。
- BUCKET_NAME:Cloud Storage 值區的名稱。在執行批次工作負載之前,Spark 會將工作負載依附元件上傳至這個值區中的
/dependencies
資料夾。 - --version:所有支援的 Dataproc 無伺服器執行階段都會將 RAPIDS 程式庫新增至 GPU 加速工作負載的每個節點。只有執行階段 1.1 版會將 XGBoost 程式庫新增至 GPU 加速工作負載的每個節點。
--properties (請參閱「Spark 資源分配屬性」):
spark.dataproc.driverEnv.LANG=C.UTF-8
和spark.executorEnv.LANG=C.UTF-8
(適用於2.2
之前的執行階段版本):這些屬性會將預設字元集設為 C.UTF-8。spark.dataproc.executor.compute.tier=premium
(必要):GPU 加速工作負載會以進階資料運算單元 (DCU) 計費。請參閱 Dataproc Serverless 加速器定價。spark.dataproc.executor.disk.tier=premium
(必要):搭載 A100-40、A100-80 或 L4 加速器的節點必須使用進階磁碟層級。spark.dataproc.executor.resource.accelerator.type=l4
(必要):您只能指定一種 GPU 類型。範例工作會選取 L4 GPU。您可以使用下列引數名稱指定下列加速器類型:GPU 類型 引數名稱 A100 40GB a100-40
A100 80GB a100-80
spark.executor.instances=5
(必要):至少須有兩個。在本範例中設為五。spark.executor.cores
(選用):您可以設定這個屬性,指定核心 vCPU 數量。L4 GPU 的有效值為4
(預設值),或8
、12
、16
、24
、48
或96
。A100 GPU 唯一有效的預設值為12
。含有 L4 GPU 和24
、48
或96
核心的設定,會將2
、4
或8
GPU 連結至每個執行緒。所有其他設定都已連結1
GPU。spark.dataproc.executor.disk.size
(必要):L4 GPU 的固定磁碟大小為 375 GB,但含有24
、48
或96
核心的設定則分別為750
、1,500
或3,000
GB。如果您在提交 L4 加速工作負載時將這個屬性設為其他值,系統會發生錯誤。如果您選取 A100 40 或 A100 80 GPU,有效的尺寸為 375g、750g、1500g、3000g、6000g 和 9000g。spark.executor.memory
(選用) 和spark.executor.memoryOverhead
(選用):您可以設定其中一個屬性,但不能同時設定兩者。未由已設屬性使用的可用記憶體量會套用至未設屬性。預設情況下,spark.executor.memoryOverhead
會設為 PySpark 批次工作負載可用記憶體的 40%,其他工作負載則為 10% (請參閱「Spark 資源分配屬性」)。下表列出可為不同 A100 和 L4 GPU 設定的記憶體最大容量。兩個屬性的最小值均為
1024
MB。A100 (40 GB) A100 (80 GB) L4 (4 個核心) L4 (8 個核心) L4 (12 個核心) L4 (16 個核心) L4 (24 個核心) L4 (48 個核心) L4 (96 個核心) 總記憶體上限 (MB) 78040 165080 13384 26768 40152 53536 113072 160608 321216 Spark RAPIDS 屬性 (選用):根據預設,Dataproc Serverless 會設定下列 Spark RAPIDS 屬性值:
spark.plugins
=com.nvidia.spark.SQLPluginspark.executor.resource.gpu.amount
=1spark.task.resource.gpu.amount
=1/$spark_executor_coresspark.shuffle.manager
=''。根據預設,此屬性未設定。NVIDIA 建議您在使用 GPU 時開啟 RAPIDS 洗牌管理工具,以提升效能。如要這麼做,請在提交工作負載時設定spark.shuffle.manager=com.nvidia.spark.rapids.RapidsShuffleManager
。spark.rapids.sql.concurrentGpuTasks
= (gpuMemoryinMB
/ 8, 4) 的最小值spark.rapids.shuffle.multiThreaded.writer.threads
= (VM 中的 CPU 核心數量 / 每個 VM 的 GPU 數量, 32) 的最小值spark.rapids.shuffle.multiThreaded.reader.threads
= (VM 中的 CPU 核心數量 / 每個 VM 的 GPU 數量, 32) 的最小值
如要設定 Spark RAPIDS 屬性,請參閱「Apache Spark 的 RAPIDS 加速器設定」一文,如要設定 Spark 進階屬性,請參閱「Apache Spark 的 RAPIDS 加速器進階設定」。
使用 GPU 加速器建立無伺服器批次工作負載
提交使用 NVIDIA L4 GPU 的 Dataproc Serverless 批次工作負載,以便執行並行 PySpark 工作。請按照下列步驟使用 gcloud CLI:
注意: