在 Dataproc 的 JupyterLab Notebook 中執行基因體學分析

本教學課程說明如何使用 DaskNVIDIA RAPIDS 和 GPU 執行單細胞基因體分析,您可以在 Dataproc 上設定這些項目。您可以設定 Dataproc,透過獨立排程器或 YARN 執行 Dask,以管理資源。

本教學課程會設定 Dataproc,搭配託管的 JupyterLab 執行個體,執行以單細胞基因體分析為主題的筆記本。在 Dataproc 上使用 Jupyter Notebook,可將 Jupyter 的互動功能與 Dataproc 支援的工作負載擴縮功能結合。使用 Dataproc 時,您可以將工作負載從一部機器水平擴展至多部機器,並視需要設定多個 GPU。

本教學課程適用於資料科學家和研究人員。本文假設您有 Python 使用經驗,並具備下列基礎知識:

目標

  • 建立已設定 GPU、JupyterLab 和開放原始碼元件的 Dataproc 執行個體。
  • 在 Dataproc 上執行筆記本

費用

在本文件中,您會使用下列 Google Cloud的計費元件:

  • Dataproc
  • Cloud Storage
  • GPUs
  • 您可以使用 Pricing Calculator,根據預測用量估算費用。

    初次使用 Google Cloud 的使用者可能符合免費試用期資格。

    完成本文所述工作後,您可以刪除建立的資源,避免繼續計費,詳情請參閱「清除所用資源」。

    事前準備

    1. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

      Roles required to select or create a project

      • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
      • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

      Go to project selector

    2. Verify that billing is enabled for your Google Cloud project.

    3. Enable the Dataproc API.

      Roles required to enable APIs

      To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

      Enable the API

    準備環境

    1. 為資源選取位置

      REGION=REGION
      

    2. 建立 Cloud Storage bucket。

      gcloud storage buckets create gs://BUCKET --location=REGION
      

    3. 將下列初始化動作複製到 bucket。

      SCRIPT_BUCKET=gs://goog-dataproc-initialization-actions-REGION
      gcloud storage cp ${SCRIPT_BUCKET}/gpu/install_gpu_driver.sh BUCKET/gpu/install_gpu_driver.sh
      gcloud storage cp ${SCRIPT_BUCKET}/dask/dask.sh BUCKET/dask/dask.sh
      gcloud storage cp ${SCRIPT_BUCKET}/rapids/rapids.sh BUCKET/rapids/rapids.sh
      gcloud storage cp ${SCRIPT_BUCKET}/python/pip-install.sh BUCKET/python/pip-install.sh
      

    建立包含 JupyterLab 和開放原始碼元件的 Dataproc 叢集

    1. 建立 Dataproc 叢集。
    gcloud dataproc clusters create CLUSTER_NAME \
        --region REGION \
        --image-version 2.0-ubuntu18 \
        --master-machine-type n1-standard-32 \
        --master-accelerator type=nvidia-tesla-t4,count=4 \
        --initialization-actions
    BUCKET/gpu/install_gpu_driver.sh,BUCKET/dask/dask.sh,BUCKET/rapids/rapids.sh,BUCKET/python/pip-install.sh
    \
        --initialization-action-timeout=60m \
        --metadata
    gpu-driver-provider=NVIDIA,dask-runtime=yarn,rapids-runtime=DASK,rapids-version=21.06,PIP_PACKAGES="scanpy==1.8.1,wget" \
        --optional-components JUPYTER \
        --enable-component-gateway \
        --single-node
    

    叢集具有下列屬性:

    • --region:叢集所在的區域
    • --image-version2.0-ubuntu18叢集映像檔版本
    • --master-machine-typen1-standard-32,主要機型
    • --master-accelerator:主要節點上的 GPU 類型和數量,四個 nvidia-tesla-t4 GPU。
    • --initialization-actions:安裝指令碼的 Cloud Storage 路徑,用於安裝 GPU 驅動程式、Dask、RAPIDS 和其他依附元件。
    • --initialization-action-timeout:初始化動作的逾時時間。
    • --metadata:傳遞至初始化動作,以使用 NVIDIA GPU 驅動程式、Dask 的獨立排程器和 RAPIDS 21.06 版設定叢集。
    • --optional-components:使用 Jupyter 選用元件設定叢集。
    • --enable-component-gateway:允許存取叢集中的 web UI。
    • --single-node:將叢集設為單一節點 (沒有 worker)。

    存取 Jupyter Notebook

    1. 在 Dataproc Google Cloud 控制台中開啟「Clusters」(叢集) 頁面。
      開啟叢集頁面
    2. 按一下叢集,然後點選「Web Interfaces」(網頁介面) 分頁標籤。
    3. 點選「JupyterLab」(JupyterLab)
    4. 在 JupyterLab 中開啟新的終端機
    5. 複製 clara-parabricks/rapids-single-cell-examples 存放區,然後查看 dataproc/multi-gpu 分支版本。

      git clone https://github.com/clara-parabricks/rapids-single-cell-examples.git
      git checkout dataproc/multi-gpu
      

    6. 在 JupyterLab 中,前往 rapids-single-cell-examples/notebooks 存放區,然後開啟 1M_brain_gpu_analysis_uvm.ipynb Jupyter Notebook。

    7. 如要清除筆記本中的所有輸出內容,請依序選取「Edit」(編輯) >「Clear All Outputs」(清除所有輸出內容)

    8. 請閱讀筆記本儲存格中的指示。筆記本會在 Dataproc 上使用 Dask 和 RAPIDS,引導您完成 100 萬個細胞的單細胞 RNA 序列工作流程,包括處理及視覺化資料。詳情請參閱「使用 RAPIDS 加速單細胞基因體學分析」。

    清除所用資源

    為避免因為本教學課程所用資源,導致系統向 Google Cloud 收取費用,請刪除含有相關資源的專案,或者保留專案但刪除個別資源。

    刪除專案

    1. In the Google Cloud console, go to the Manage resources page.

      Go to Manage resources

    2. In the project list, select the project that you want to delete, and then click Delete.
    3. In the dialog, type the project ID, and then click Shut down to delete the project.

    刪除個別資源

    1. 刪除 Dataproc 叢集。
      gcloud dataproc clusters delete cluster-name \
          --region=region
      
    2. 刪除 bucket:
      gcloud storage buckets delete BUCKET_NAME

    後續步驟