aws 在ecs外部實例上運行gpu負載

參考資料

  • https://docs.amazonaws.cn/zh_cn/AmazonECS/latest/developerguide/ecs-gpu.html
  • https://docs.amazonaws.cn/AWSEC2/latest/UserGuide/accelerated-computing-instances.html#gpu-instances
  • https://docs.amazonaws.cn/AWSEC2/latest/UserGuide/install-nvidia-driver.html
  • https://aws.amazon.com/cn/blogs/containers/running-gpu-based-container-applications-with-amazon-ecs-anywhere/
  • https://github.com/aws/containers-roadmap/issues/88

ecs支持的gpu負載的實例類型包括p2、p3、g3、g4 和 g5

ecs提供了經過優化的gpu ami

  • 預裝了NVIDIA內核驅動和docker GPU運行時

注意事項

  • 注冊外部實例到ecs集群時,必須在腳本中添加--enable-gpu
  • 在ecs代理中將ECS_ENABLE_GPU_SUPPORT 設置為 true
  • 在容器定義中指定gpu資源,則ecs會分配gpu運行時
  • nvidia需要在容器內設置環境變量才能正常運行,ecs設置 NVIDIA_VISIBLE_DEVICES 環境變量值設置為ecs分配給容器的 GPU 設備 ID 列表

啟動ec2實例并運行pytorch程序

啟動g4dn.xlarge實例

使用nvidia-smi

查看gpu基礎信息

$ nvidia-smi
Thu Apr 13 16:13:29 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.85.12    Driver Version: 525.85.12    CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Tesla T4            On   | 00000000:00:1E.0 Off |                    0 |
| N/A   22C    P8     9W /  70W |      2MiB / 15360MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------++-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

參數解釋

img

查看全部設備

$ nvidia-smi -L
GPU 0: Tesla T4 (UUID: GPU-0bef2a14-5ece-86c0-e4f8-ef82122a1172)

查看系統拓撲

$ nvidia-smi topo --matrixGPU0    CPU Affinity    NUMA Affinity
GPU0     X      0-3             N/ALegend:X    = SelfSYS  = Connection traversing PCIe as well as the SMP interconnect between NUMA nodes (e.g., QPI/UPI)NODE = Connection traversing PCIe as well as the interconnect between PCIe Host Bridges within a NUMA nodePHB  = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU)PXB  = Connection traversing multiple PCIe bridges (without traversing the PCIe Host Bridge)PIX  = Connection traversing at most a single PCIe bridgeNV#  = Connection traversing a bonded set of # NVLinks

使用pytorch運行負載

python pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple/ some-package --trusted-host mirrors.aliyun.com

打印詳細i信息

// main.py
import torch
print(torch.__version__)
print(torch.cuda.is_available())
print(torch.cuda.device_count())
print(torch.cuda.device(0))
print(torch.cuda.get_device_name(0))
output:
1.8.1+cu111
True
1
<torch.cuda.device object at 0x7fd0dace8510>
Tesla T4

示例程序

https://github.com/pytorch/examples

git clone git@github.com:pytorch/examples.git

優化ami上的docker環境

docker上的nvidia運行時參數如下

$ cat /etc/docker/daemon.json
{"runtimes": {"nvidia": {"path": "nvidia-container-runtime","runtimeArgs": []}}
}

本地測試

# nvidia-smi是nvidia 的系統管理界面
docker run --rm --gpus all nvidia/cuda:11.0.3-base-ubuntu20.04 nvidia-smi
# 指定gpu參數
docker run --rm --gpus '"device=1,2"' nvidia/cuda nvidia-smi --query-gpu=uuid --format=csv
docker run --rm --runtime=nvidia \-e NVIDIA_VISIBLE_DEVICES=1,2 \nvidia/cuda nvidia-smi --query-gpu=uuid --format=csv
# 啟用所有gpu
docker run --rm --runtime=nvidia \-e NVIDIA_VISIBLE_DEVICES=all nvidia/cuda:11.0.3-base-ubuntu20.04 nvidia-smi
# 查詢uuid并使用
nvidia-smi -i 3 --query-gpu=uuid --format=csv
docker run --gpus device=GPU-18a3e86f-4c0e-cd9f-59c3-55488c4b0c24 \nvidia/cuda nvidia-smi

在ecs中的任務定義

目前fargate不支持gpu負載

https://github.com/aws/containers-roadmap/issues/88

mnist示例

https://github.com/pytorch/examples/tree/main/mnist

$ tree 
main.py
requirements.txt
dockerfile

本地構建鏡像,最終大概有5g大小

FROM public.ecr.aws/docker/library/python:3.7
WORKDIR /test_load
COPY . .
run pip3 install -r requirements.txt -i https://pypi.douban.com/simple
entrypoint python
cmd main.py

上傳到ecr,在任務定義中引用

{"containerDefinitions": [{"memory": 80,"essential": true,"name": "gpu","image": "nvidia/cuda:11.0.3-base","resourceRequirements": [{"type":"GPU","value": "1"}],"command": ["sh","-c","nvidia-smi"],"cpu": 100}],"family": "example-ecs-gpu"
}

將之前啟動的本地實例加入ecs集群中

curl --proto "https" -o "/tmp/ecs-anywhere-install.sh" "https://amazon-ecs-agent.s3.cn-north-1.amazonaws.com.cn/ecs-anywhere-install-latest.sh" 
bash /tmp/ecs-anywhere-install.sh --region "cn-north-1" --cluster "worktest" --activation-id "840527d1-4b24-45af-b1d3-bea6a39c140f" --activation-code "xxxxxxxx+bFbv" --enable-gpu

腳本內容

https://amazon-ecs-agent.s3.cn-north-1.amazonaws.com.cn/ecs-anywhere-install-latest.sh

如何對已斷開連接的 Amazon ECS 代理進行問題排查?

https://repost.aws/zh-Hans/knowledge-center/ecs-agent-disconnected-linux2-ami

故障和解決

(1)配置額外憑證干擾腳本運行

外部實例不應具有本地定義的預配置實例憑據鏈,因為這會干擾注冊腳本

哪怕配置實例角色都不行

level=warn time=2023-04-13T18:12:14Z msg="Not able to get EC2 Instance ID from IMDS, using EC2 Instance ID from saved state: ''" module=agent.go
level=info time=2023-04-13T18:12:14Z msg="Cluster was successfully restored" cluster="worktest"
level=warn time=2023-04-13T18:12:14Z msg="AppNet agent container tarball unavailable: /managed-agents/serviceconnect/ecs-service-connect-agent.interface-v1.tar" error="stat /managed-agents/serviceconnect/ecs-service-connect-agent.interface-v1.tar: no such file or directory"
level=warn time=2023-04-13T18:12:14Z msg="ServiceConnect Capability: No service connect capabilities were found for Appnet version:" image=""
level=info time=2023-04-13T18:12:14Z msg="Restored from checkpoint file" containerInstanceARN="arn:aws-cn:ecs:cn-north-1:xxxxxxx:container-instance/worktest/65a5fe8ed62643a7a28e52ececbe1d5c" cluster="worktest"
level=info time=2023-04-13T18:12:14Z msg="Fetching Instance ID Document has been disabled" module=client.go
level=info time=2023-04-13T18:12:14Z msg="Remaining mem: 15704" module=client.go
level=error time=2023-04-13T18:12:14Z msg="Unable to register as a container instance with ECS: InvalidParameterException: The identity document and identity document signature were not valid." module=client.go
level=error time=2023-04-13T18:12:14Z msg="Error re-registering container instance" error="InvalidParameterException: The identity document and identity document signature were not valid."

ssm會創建臨時憑證,使用注冊id作為識別碼(因此實例本身不需要配置任何憑證)

# aws configure listName                    Value             Type    Location----                    -----             ----    --------profile                <not set>             None    None
access_key     ****************S262 shared-credentials-file
secret_key     ****************rSzM shared-credentials-fileregion                <not set>             None    None
# aws sts get-caller-identity  --region cn-north-1
{"Account": "xxxxxxx","UserId": "AROAQRIBxxxIH3NQPIDG:mi-0b7270b56b35ac6cc","Arn": "arn:aws-cn:sts::xxxxxxx:assumed-role/ecsExternalInstanceRole/mi-0b7270b56b35ac6cc"
}

清理環境

sudo systemctl stop ecs amazon-ssm-agent
sudo yum remove -y amazon-ecs-init amazon-ssm-agent
sudo rm -rf /var/lib/ecs /etc/ecs /var/lib/amazon/ssm /var/log/ecs /var/log/amazon/ssm

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/19463.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/19463.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/19463.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

LeetCode 63.不同路徑Ⅱ

思路&#xff1a; 在有障礙物的地方增加一個判斷即可 class Solution { public:int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {int dp[105][105];int mobstacleGrid.size();int nobstacleGrid[0].size();for(int i0;i<m;i){for(int j0…

K8s集群之 存儲卷 PV PVC

目錄 默寫 1 如何將pod創建在指定的Node節點上 2 污點的種類(在node上設置) 一 掛載存儲??????? 1 emptyDir存儲卷 2 hostPath存儲卷 ①在 node01 節點上創建掛載目錄 ② 在 node02 節點上創建掛載目錄 ③ 創建 Pod 資源 ④ 在master上檢測一下&#xff1a;…

C++ vector 模擬實現

vector的底層也是一個動態數組&#xff0c;他與 string 的區別就是&#xff0c;string 是專門用來存儲字符類數據的&#xff0c;為了兼容C語言&#xff0c;使用C語言的接口&#xff0c;在string的動態數組內都會都開一塊空間用來存 \0 &#xff0c;而vector則不會。 首先我們要…

【Linux多線程】認識多線程創建線程

文章目錄 什么是多線程為什么稱linux下的線程是輕量級進程呢&#xff1f; 線程的優點線程的缺點線程異常線程和進程創建線程1.pthread_create2.pthread_self 什么是多線程 進程是正在運行的程序的實例&#xff0c;而線程&#xff08;thread&#xff09;是進程中的一個執行路線…

python 刪除pdf 空白頁

環境 python 3.10 PyPDF2 3.0.1 安裝 pip install PyPDF2流程 將空白頁和內容頁讀取出來&#xff0c;看看內部結構有什么不同以此為依據&#xff0c;遍歷整個PDF 文件&#xff0c;標記處有內容的頁面&#xff0c;寫入到另外一個PDF文件。 python 代碼 # 每一個頁都是一個…

Springboot郵件發送配置

Springboot郵件發送配置 pom.xml依賴&#xff1a; <dependency><groupId>org.eclipse.angus</groupId><artifactId>jakarta.mail</artifactId><version>2.0.3</version> </dependency> <dependency><groupId>or…

跨域的解決方案

1. 計算機更改跨域 1.C盤->Windows->System32->drivers->etc 2.修改hosts 文件2. Chrome瀏覽器的跨域設置 操作步驟&#xff1a;1.打開我的電腦——C盤 新建一個文件夾&#xff0c;命名為MyChromeDevUserData2.右鍵——Chrome——快捷方式——目標&#xff0c;在…

ChatGPT成知名度最高生成式AI產品,使用頻率卻不高

5月29日&#xff0c;牛津大學、路透社新聞研究所聯合發布了一份生成式AI&#xff08;AIGC&#xff09;調查報告。 在今年3月28日—4月30日對美國、英國、法國、日本、丹麥和阿根廷的大約12,217人進行了調查&#xff0c;深度調研他們對生成式AI產品的應用情況。 結果顯示&…

ElementUI之el-table標題列中顯示el-tooltip

ElementUI之el-table標題列中顯示el-tooltip 文章目錄 ElementUI之el-table標題列中顯示el-tooltip1. el-table標題列中顯示el-tooltip2. 實現代碼3. 展示效果 1. el-table標題列中顯示el-tooltip 在el-table-column標簽內添加具名插槽v-slot:header 在el-tooltip標簽中使用具…

【幾何】輸入0-360度任意的角度,求上面直線與橢圓相切點的坐標計算公式

?輸入0-360度任意的角度,求上面直線與橢圓相切點的坐標計算公式 使用積分計算 使用到的公式有橢圓公式: x 2 a 2 + y 2 b 2 = 1 \frac{x^2}{a^2}+\frac{y^2}{b^2} = 1 a2x2?+b2y2?=1 平面旋轉公式 X r = cos ? θ ? ( X s ? X O ) ? sin ? θ ? ( Y s ? Y O ) + X …

端午節粽子龍舟主題互動趣味小游戲效果是什么

端午三天樂&#xff0c;無論節日當天還是之前&#xff0c;行業商家都可以自己的品牌為主借勢營銷&#xff0c;趣味活動形式玩法和內容呈現達成多種效果&#xff0c;品牌傳播、公眾號漲粉、線下互動、商品促銷、用戶促活等。 在【雨科】平臺擁有多款端午節互動小游戲類型&#…

網易狼人殺 設置點擊自動發言

我們玩網易狼人殺 剛開始 都會發現 要按住麥克風才能發言 不得不說 相當的麻煩 我們可以點擊如下圖 右上角這個設置的齒輪 新彈出的設置面板上 勾選這個點擊發言 然后 我們只需要 點一下 就可以進入發言狀態 然后 再點一下即可停止發言 會方便非常多

zabbix事件告警監控:如何實現對相同部件觸發器告警及恢復的強關聯

有一定Zabbix使用經驗的小伙伴可能會發現&#xff0c;接收告警事件時&#xff0c;其中可能包含著大量不同的部件名&#xff0c;同一部件的事件在邏輯上具有很強關聯性&#xff0c;理論上應保持一致的告警/恢復狀態&#xff0c;但Zabbix默認并未對它們進行關聯&#xff0c;直接后…

AIGC降重:如何2分鐘降低論文AI率和查重率?推薦使用SpeedAI科研小助手

確保學術論文的獨立性與誠信性&#xff0c;對于學業的成就及學位的獲取至關重要&#xff0c;其中&#xff0c;論文的人工智能查重與降低AIGC相似度扮演著核心角色。 常規的查重手段主要圍繞查重軟件的運用和個體的自行審查&#xff1b;而降重則通常通過語句重組、同義替換、內…

單細胞分析(Signac): PBMC scATAC-seq 基因組區域可視化

引言 在本教學指南中&#xff0c;我們將探討由10x Genomics公司提供的人類外周血單核細胞&#xff08;PBMCs&#xff09;的單細胞ATAC-seq數據集。 加載包 首先加載 Signac、Seurat 和我們將用于分析人類數據的其他一些包。 if (!requireNamespace("EnsDb.Hsapiens.v75&qu…

ModuleNotFoundError: No module named ‘osgeo‘

顯示無osgeo模塊 pip install osgeo顯示失敗 方法&#xff1a; 確保你已經安裝了正確的依賴項&#xff0c;例如GDAL、GEOS和PROJ等。 方法1&#xff1a;pip install gdal 失敗 方法2&#xff1a;官網下載失敗&#xff0c;下載地址&#xff1a;https://www.lfd.uci.edu/~gohl…

在Linux系統中,使用OpenSSL生成私有證書文件,并提取私鑰的步驟如下:

在Linux系統中&#xff0c;使用OpenSSL生成私有證書文件&#xff0c;并提取私鑰的步驟如下&#xff1a; 生成私鑰&#xff08;如果還沒有私鑰的話&#xff09;&#xff1a; openssl genpkey -algorithm RSA -out private.pem -pkeyopt rsa_keygen_bits:2048 生成自簽名證書&…

設置自動刷新數據透視表的數據源

數據透視表數據源的自動刷新 一般情況操作&#xff1a; 自動刷新操作&#xff1a; 1、定義名稱名稱 引用位置&#xff1a;OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A),COUNTA(Sheet1!$1:$1)) 2、數據透視表的數據源更改為【源數據】—— 即前面定義的名稱 3、數據——全部…

Java多線程——觀測線程狀態

線程可以處于以下幾個狀態&#xff1a; NEW&#xff1a;尚未啟動的線程處于此狀態&#xff1b; RUNNABLE&#xff1a;在Java虛擬機中執行的線程處于此狀態&#xff1b; BLOCKED&#xff1a;被阻塞等待監視器鎖定的線程處于此狀態&#xff1b; WAITING&#xff1a;正在等待…

區塊鏈技術和應用二

前言 學習長安鏈的一些基本原理 官網&#xff1a;長安鏈開源文檔 b站課程&#xff1a;區塊鏈基礎與應用 一、共識算法 1.1 POW工作量證明 最長鏈共識&#xff0c;沒聽明白 1.2 51%攻擊 二、區塊鏈的發展 2.1 區塊鏈1.0到3.0 2.2 共有鏈、聯盟鏈、私有鏈 2.3 發展趨勢 2.4 擴…