高性能機器學習分佈
我們目前正在重建鯊魚以利用渦輪機。在完成此操作之前,請確保您使用.exe釋放或SHARK-1.0分支的結帳,以進行工作鯊魚
其他用戶請確保您從這裡使用最新的供應商驅動程序和Vulkan SDK,如果您使用的是Vulkan Check Check vulkaninfo在終端窗口中工作
從(先決條件)[https://github.com/nod-ai/shark-studio#install-your-hardware-drivers]中安裝驅動程序
下載穩定版本或最新的鯊魚1.0預釋放。
雙擊.EXE,或從命令行(推薦)運行,您應該在瀏覽器中使用UI。
如果您有自定義模型,則將它們放在.exe所在的models/目錄中。
享受。
cd )更改為.EXE文件夾。然後從命令提示符中運行EXE。這樣,如果發生錯誤,您將能夠將其剪切並尋求幫助。 (如果它總是為您工作而沒有錯誤,則可以雙擊EXE)--ui=web命令參數。 git clone https://github.com/nod-ai/SHARK.git
cd SHARK目前,鯊魚正在main分支上為渦輪機重建。目前,除非您正在進行重建工作,否則您強烈不鼓勵使用main ,並且不應該期望那裡的代碼生成圖像生成的工作應用程序,因此現在您需要切換到SHARK-1.0分支並使用穩定的代碼。
git checkout SHARK-1.0以下設置說明假定您在此分支上。
set-executionpolicy remotesigned. / setup_venv.ps1 # You can re-run this script to get the latest version./setup_venv.sh
source shark1.venv/bin/activate(shark1.venv) PS C:gshark > cd .appsstable_diffusionweb
(shark1.venv) PS C:gsharkappsstable_diffusionweb > python .index.py(shark1.venv) > cd apps/stable_diffusion/web
(shark1.venv) > python index.py
(shark1.venv) PS C:gshark > python .appsstable_diffusionscriptsmain.py -- app = " txt2img " -- precision = " fp16 " -- prompt = " tajmahal, snow, sunflowers, oil on canvas " -- device = " vulkan " python3.11 apps/stable_diffusion/scripts/main.py --app=txt2img --precision=fp16 --device=vulkan --prompt= " tajmahal, oil on canvas, sunflowers, 4k, uhd "您可以用cpu替換vulkan ,以在CPU上或使用cuda運行以在CUDA設備上運行。如果您有多個Vulkan設備,則可以使用--device=vulkan://1等來解決它們
AMD 7900XTX上的輸出看起來像:
Average step time: 47.19188690185547ms/it
Clip Inference time (ms) = 109.531
VAE Inference time (ms): 78.590
Total image generation time: 2.5788655281066895sec這是生成的一些樣本:


如果您在硬件上運行它有任何麻煩,請在Shark Discord服務器上找到我們。
此步驟為Python設置了一個新的Virtualenv
python --version # Check you have 3.11 on Linux, macOS or Windows Powershell
python -m venv shark_venv
source shark_venv/bin/activate # Use shark_venv/Scripts/activate on Windows
# If you are using conda create and activate a new conda env
# Some older pip installs may not be able to handle the recent PyTorch deps
python -m pip install --upgrade pipMACOS金屬用戶請安裝https://sdk.lunarg.com/sdk/download/latest/mac/vulkan-sdk.dmg,並啟用“系統寬安裝”
此步驟PIP在Linux Python 3.8、3.10和3.11以及MacOS / Windows Python 3.11上安裝鯊魚和相關軟件包
pip install nodai-shark -f https://nod-ai.github.io/SHARK/package-index/ -f https://llvm.github.io/torch-mlir/package-index/ -f https://nod-ai.github.io/SRT/pip-release-links.html --extra-index-url https://download.pytorch.org/whl/nightly/cpupytest tank/test_models.py有關我們的Pytest Suite和CLI的更詳細的演練,請參見Tank/readme.md。
curl -O https://raw.githubusercontent.com/nod-ai/SHARK/main/shark/examples/shark_inference/resnet50_script.py
# Install deps for test script
pip install --pre torch torchvision torchaudio tqdm pillow gsutil --extra-index-url https://download.pytorch.org/whl/nightly/cpu
python ./resnet50_script.py --device= " cpu " # use cuda or vulkan or metalcurl -O https://raw.githubusercontent.com/nod-ai/SHARK/main/shark/examples/shark_inference/minilm_jit.py
# Install deps for test script
pip install transformers torch --extra-index-url https://download.pytorch.org/whl/nightly/cpu
python ./minilm_jit.py --device= " cpu " # use cuda or vulkan or metal如果要使用python3.11並使用TF導入工具,則可以使用以下環境變量,例如:set USE_IREE=1用於上游iree
# PYTHON=python3.11 VENV_DIR=0617_venv IMPORTER=1 ./setup_venv.sh
python -m shark.examples.shark_inference.resnet50_script --device= " cpu " # Use gpu | vulkan
# Or a pytest
pytest tank/test_models.py -k " MiniLM "如果您是Torch-Mlir開發人員或IREE開發人員,並且希望測試本地更改,則可以使用pip uninstall torch-mlir和 /或pip uninstall iree-compiler iree-runtime ,並在本地構建Python bitthon bitthon,並在此處提到的IREE和此處提到的Torch-Mlir,並將其設置為Pythonth。
如何將本地建造的火炬與鯊魚一起使用:
1.) Run ` ./setup_venv.sh in SHARK ` and activate ` shark.venv ` virtual env.
2.) Run ` pip uninstall torch-mlir ` .
3.) Go to your local Torch-MLIR directory.
4.) Activate mlir_venv virtual envirnoment.
5.) Run ` pip uninstall -r requirements.txt ` .
6.) Run ` pip install -r requirements.txt ` .
7.) Build Torch-MLIR.
8.) Activate shark.venv virtual environment from the Torch-MLIR directory.
8.) Run ` export PYTHONPATH= ` pwd ` /build/tools/torch-mlir/python_packages/torch_mlir: ` pwd ` /examples ` in the Torch-MLIR directory.
9.) Go to the SHARK directory.現在,鯊魚將使用您的本地構建火炬 - 馬里爾倉庫。
要產生單個調度的基準,您可以添加--dispatch_benchmarks=All --dispatch_benchmarks_dir=<output_dir>到您的pytest命令行參數。如果您只想編譯特定的調度,則可以用空格分離字符串而不是"All"指定它們。例如 - --dispatch_benchmarks="0 1 2 10"
例如,在CUDA上生成和運行Minilm的調度基準:
pytest -k "MiniLM and torch and static and cuda" --benchmark_dispatches=All -s --dispatch_benchmarks_dir=./my_dispatch_benchmarks
給定命令將填充<dispatch_benchmarks_dir>/<model_name>/帶有ordered_dispatches.txt ,列出並列出並訂購了調度及其潛伏期,以及包含.mlir,.vmfb的每個調度文件夾,以及該調度的基準標記的結果。
如果您想將其合併到Python腳本中,則可以在初始化SharkInference時傳遞dispatch_benchmarks和dispatch_benchmarks_dir命令,並且在編譯時將生成基準測試。例如:
shark_module = SharkInference(
mlir_model,
device=args.device,
mlir_dialect="tm_tensor",
dispatch_benchmarks="all",
dispatch_benchmarks_dir="results"
)
輸出將包括:
有關如何從鯊魚罐中運行模型測試和基準測試的進一步說明,請參見Tank/readme.md。
from shark.shark_importer import SharkImporter
# SharkImporter imports mlir file from the torch, tensorflow or tf-lite module.
mlir_importer = SharkImporter(
torch_module,
(input),
frontend="torch", #tf, #tf-lite
)
torch_mlir, func_name = mlir_importer.import_mlir(tracing_required=True)
# SharkInference accepts mlir in linalg, mhlo, and tosa dialect.
from shark.shark_inference import SharkInference
shark_module = SharkInference(torch_mlir, device="cpu", mlir_dialect="linalg")
shark_module.compile()
result = shark_module.forward((input))
from shark.shark_inference import SharkInference
import numpy as np
mhlo_ir = r"""builtin.module {
func.func @forward(%arg0: tensor<1x4xf32>, %arg1: tensor<4x1xf32>) -> tensor<4x4xf32> {
%0 = chlo.broadcast_add %arg0, %arg1 : (tensor<1x4xf32>, tensor<4x1xf32>) -> tensor<4x4xf32>
%1 = "mhlo.abs"(%0) : (tensor<4x4xf32>) -> tensor<4x4xf32>
return %1 : tensor<4x4xf32>
}
}"""
arg0 = np.ones((1, 4)).astype(np.float32)
arg1 = np.ones((4, 1)).astype(np.float32)
shark_module = SharkInference(mhlo_ir, device="cpu", mlir_dialect="mhlo")
shark_module.compile()
result = shark_module.forward((arg0, arg1))
鯊魚的維持是為了支持ML模型中的最新創新:
| TF擁抱面模型 | 鯊魚CPU | 鯊魚庫達 | 鯊魚金屬 |
|---|---|---|---|
| 伯特 | |||
| Distilbert | |||
| GPT2 | |||
| 盛開 | |||
| 穩定的擴散 | |||
| 視覺變壓器 | |||
| RESNET50 |
有關鯊魚支持的模型的完整列表,請參閱Tank/readme.md。
#torch-mlir頻道 - 這是最活躍的通信頻道torch-mlir部分NOD.AI鯊魚已根據Apache 2.0許可證的條款獲得許可,其LLVM例外。有關更多信息,請參見許可證。