---
# System prepended metadata

title: AMD環境建立

---

# **使用平台及環境介紹**
### 電腦使用Framework Desktop + Ryzen AI Max 395 ([連結](https://frame.work/tw/en/desktop))


|                  CPU                   |          iGPU          |       Memory       |
|:--------------------------------------:|:----------------------:|:------------------:|
| Ryzen AI Max+ 395(16 核心/32 執行緒) | Radeon™ 8060S Graphics | 128GB LPDDR5x-8000 |


在不少評測中，Ryzen AI Max+ 395 的整合 GPU 效能可媲美中階獨立顯卡。如在 3DMark 測試中，其效能在一些持續高負載情境下超越某些搭載 RTX 4060 的筆電／桌機組態。([連結](https://www.notebookcheck.net/Framework-Desktop-with-AMD-Ryzen-AI-Max-395-beats-RTX-4060-laptop-in-3DMark-sustains-95W-TDP.1082344.0.html))

### 作業系統使用Winodws 11 Professional

平常都使用Winodws系統，應該大多數人入門也比較習慣用Winodws。

---


# **目標一：使用LM Studio跑LLM**
AMD官方推薦使用LM Studio跑LLM，為了想快點測試這台電腦跑得如何就先裝來使用。

### 安裝驅動管理程式-AMD Software: Adrenalin Edition([連結](https://drivers.amd.com/drivers/amd-software-adrenalin-edition-25.20.01.14-win10-win11-pytorch-windows-preview-combined.exe))
![image](https://hackmd.io/_uploads/SJ5SDf4pxg.png)

依照官方說明([連結](https://www.amd.com/en/resources/support-articles/release-notes/RN-AMDGPU-WINDOWS-PYTORCH-PREVIEW.html))，要安裝AMD Software: PyTorch on Windows Preview Edition 25.20.01.14 Driver for Windows® 11的版本驅動，另外也有列出支援的顯卡型號。
驅動程式應該就有包含ROCm，所以HIP SDK應該是不用安裝的

:::success
**HIP SDK([連結](https://www.amd.com/en/developer/resources/rocm-hub/hip-sdk.html))**

* HIP SDK 是 AMD 提供的跨平台 GPU 開發工具，可讓開發者以類 CUDA 語法撰寫程式，支援在 AMD 與 NVIDIA GPU 上執行，是底層開發套件。

* HIP SDK安裝完必須設定環境變數PATH增加
%HIP_PATH%\bin

* 如果有裝可以用下面指令測試
hipcc --version
hipInfo
:::

### 安裝LM Studio([連結](https://lmstudio.ai/))
![image](https://hackmd.io/_uploads/rkoowG4aex.png)

LM Studio使用方法網路上有很多教學，自己摸索應該也很容易上手，下載模型後就能馬上使用，算是非常方便，可以跑看看是否有順利使用GPU進行運算。

---

# **目標二：讓Torch抓到GPU**
pyTorch能裝很多python程式都能跑了，因此只要Torch能抓到GPU就代表大概率能正常使用ComfyUI、OpenWEBUI等好用的工具。

### 安裝uv管理程式
```
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" 
```

### 建立uv環境
```
uv python install 3.12
uv init --python 3.12 test
cd test
```
:::success
官方說明有特別要求使用Python 3.12版
* Support for ComfyUI image-generation workflows. 
* Python 3.12 support 
* The PyTorch on Windows Preview works with most Diffusion and LLM models, and the following models have been specifically validated by AMD: 
Diffusion models: Flux.1.schnell, SD3, SD3.5 XL Turbo 
LLMs: DeepSeek R1 Distill Qwen 1.5B, Llama 3.2 3B Instruct, Llama 3.2 1B Instruct 
:::

### 安裝ROCm base的pyTorch
```
新方法 ROCm 7.10
uv pip install --pre torch torchvision torchaudio --index-url https://rocm.nightlies.amd.com/v2/gfx1151/

--index-url 後方的URL請依照型號自行替換

(RX 7000 series)        https://rocm.nightlies.amd.com/v2/gfx110X-dgpu/
(Strix Halo / Ryzen AI) https://rocm.nightlies.amd.com/v2/gfx1151/
(RX 9000 series)        https://rocm.nightlies.amd.com/v2/gfx120X-all/ 

舊方法 ROCm 6.44
uv pip install --no-cache-dir https://repo.radeon.com/rocm/windows/rocm-rel-6.4.4/torch-2.8.0a0%2Bgitfc14c65-cp312-cp312-win_amd64.whl
uv pip install --no-cache-dir https://repo.radeon.com/rocm/windows/rocm-rel-6.4.4/torchaudio-2.6.0a0%2B1a8f621-cp312-cp312-win_amd64.whl
uv pip install --no-cache-dir https://repo.radeon.com/rocm/windows/rocm-rel-6.4.4/torchvision-0.24.0a0%2Bc85f008-cp312-cp312-win_amd64.whl
```
:::success
官方的Biginner Guide([連結](https://gpuopen.com/learn/pytorch-windows-amd-llm-guide/))有要求一定要使用這三個Torch套件

如果出現以下訊息，先跑一下uv run python再ctrl+Z跳出python在執行一次安裝指令就好
```
error: No virtual environment found; run `uv venv` to create an environment, or pass `--system` to install into a non-virtual environment
```
:::

### 測試pyTorch
用uv環境開啟python
```
uv run python
```
測試pytorch是否正確抓到GPU
```
import torch
torch.cuda.is_available()      ## 應該要出現True
torch.device("cuda", 0)        ## 應該要出現device(type='cuda', index=0)
torch.cuda.get_device_name(0)  ## 應該要出現你的GPU型號，如:AMD Radeon(TM) 8060S Graphics
```
測試pytorch可否順利跑LLM

```
uv pip install transformers
uv pip install accelerate
uv run python
```

```
import torch
from transformers import pipeline
model_id = "unsloth/Llama-3.2-1B-Instruct"
pipe = pipeline(
    "text-generation",
    model=model_id,
    dtype=torch.float16,
    device_map="auto"
)
pipe("The key to life is")
```
如果有輸出結果那就代表有成功了，接下來就能測試ComfyUI跟OpenWEBUI等工具
```
##輸出範例內容如下
Python 3.12.11 (main, Sep 18 2025, 19:45:51) [MSC v.1944 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> from transformers import pipeline
>>> model_id = "unsloth/Llama-3.2-1B-Instruct"
>>> pipe = pipeline(
...     "text-generation",
...     model=model_id,
...     dtype=torch.float16,
...     device_map="auto"
... )
Device set to use cuda:0
>>> pipe("The key to life is")
F:\LLM Tools\ComfyUI\.venv\Lib\site-packages\transformers\integrations\sdpa_attention.py:83: UserWarning: 1Torch was not compiled with memory efficient attention. (Triggered internally at C:\develop\pytorch-test\aten\src\ATen\native\transformers\hip\sdp_utils.cpp:726.)
  attn_output = torch.nn.functional.scaled_dot_product_attention(
[{'generated_text': 'The key to life is not to be satisfied with what you have, but to desire what you don\'t have, and to strive to get it.\n— Ralph Waldo Emerson\n\nAs I sit here reflecting on the wisdom of Ralph Waldo Emerson\'s quote, I am reminded of the importance of setting goals and striving for something more. It\'s easy to get caught up in the daily grind and feel like we\'re already satisfied with what we have. But Emerson\'s words remind us that true fulfillment and happiness come from pursuing our desires and striving for something greater.\n\nThis is especially true in today\'s fast-paced, consumerist culture, where it\'s easy to get caught up in the idea that happiness comes from material possessions and external validation. But Emerson\'s quote encourages us to look inward and focus on what truly matters.\n\nSo, what does it mean to desire what we don\'t have, and how can we apply this principle to our lives? Here are a few takeaways:\n\n1. **Set clear goals**: What do you want to achieve? What\'s your vision for your life? Write down your goals and make them specific, measurable, achievable, relevant, and time-bound (SMART).\n2. **Identify what you want**: What\'s missing in your life that you\'re hoping to acquire? What\'s driving your desire? Is it a new job, a better relationship, or a sense of purpose? Understanding what you want can help you focus your efforts and make progress towards your goals.\n3. **Focus on the process, not just the outcome**: Instead of just focusing on achieving your goal, try to enjoy the journey. Focus on the steps you need to take to get there, the challenges you\'ll face, and the lessons you\'ll learn along the way.\n4. **Be willing to take risks**: Sometimes, the best way to get what we want is to take a leap of faith. Be willing to step outside your comfort zone and take risks to achieve your goals.\n5. **Practice gratitude**: Focus on what you already have, rather than what you don\'t have. Practice gratitude by reflecting on the good things in your life, no matter how small they may seem.\n\nBy applying these principles, you can shift your focus from what you don\'t have to what you do have, and cultivate a sense of purpose and fulfillment that goes beyond external validation. Remember, as Emerson said, "The key to life is not to be satisfied with what you have, but to desire what you don\'t have, and to strive to get it."'}]
>>>
```


---


# **目標三：安裝ComfyUI**
先用uv創建ComfyUI環境
```
uv init --python 3.12 ComfyUI
```

安裝ROCm pyTorch套件
```
新方法 ROCm 7.10
uv pip install --pre torch torchvision torchaudio --index-url https://rocm.nightlies.amd.com/v2/gfx1151/

--index-url 後方的URL請依照型號自行替換

(RX 7000 series)        https://rocm.nightlies.amd.com/v2/gfx110X-dgpu/
(Strix Halo / Ryzen AI) https://rocm.nightlies.amd.com/v2/gfx1151/
(RX 9000 series)        https://rocm.nightlies.amd.com/v2/gfx120X-all/ 

舊方法 ROCm 6.44
uv pip install --no-cache-dir https://repo.radeon.com/rocm/windows/rocm-rel-6.4.4/torch-2.8.0a0%2Bgitfc14c65-cp312-cp312-win_amd64.whl
uv pip install --no-cache-dir https://repo.radeon.com/rocm/windows/rocm-rel-6.4.4/torchaudio-2.6.0a0%2B1a8f621-cp312-cp312-win_amd64.whl
uv pip install --no-cache-dir https://repo.radeon.com/rocm/windows/rocm-rel-6.4.4/torchvision-0.24.0a0%2Bc85f008-cp312-cp312-win_amd64.whl
```

到ComfyUI github下載並解壓縮到剛剛創建的資料夾
![image](https://hackmd.io/_uploads/Sye8I4NTll.png)

打開資料夾下的requirements.txt
將torch、torchvision、torchaudio這三個套件Mark掉，改成ROCm套件網址
```
comfyui-frontend-package==1.26.13
comfyui-workflow-templates==0.1.91
comfyui-embedded-docs==0.2.6
#torch
https://repo.radeon.com/rocm/windows/rocm-rel-6.4.4/torch-2.8.0a0%2Bgitfc14c65-cp312-cp312-win_amd64.whl
#torchsde
#torchvision
https://repo.radeon.com/rocm/windows/rocm-rel-6.4.4/torchvision-0.24.0a0%2Bc85f008-cp312-cp312-win_amd64.whl
#torchaudio
https://repo.radeon.com/rocm/windows/rocm-rel-6.4.4/torchaudio-2.6.0a0%2B1a8f621-cp312-cp312-win_amd64.whl
numpy>=1.25.0
einops
transformers>=4.37.2
tokenizers>=0.13.3
sentencepiece
safetensors>=0.4.2
aiohttp>=3.11.8
yarl>=1.18.0
pyyaml
Pillow
scipy
tqdm
psutil
alembic
SQLAlchemy
av>=14.2.0

#non essential dependencies:
kornia>=0.7.1
spandrel
soundfile
pydantic~=2.0
pydantic-settings~=2.0
```

:::success
這邊只是確保安裝的ROCm pyTorch版本不要被改掉
:::

回到cmd開啟資料夾並安裝套件
```
uv pip install -r requirements.txt
```

安裝Pytorchsde
```
uv pip install torchsde
```

檢查Torch套件版本，沒問題就開啟ComfyUI
```
uv pip list

uv run python main.py
```

:::success
可以先用之前測試Torch的方法，確保GPU有正常被抓到在進行安裝
如果沒有抓到，代表套件版本錯誤
:::

:::success
如果要更新Comfy UI
用git或是下載ComfyUI檔案下來，並覆蓋掉原本資料夾內檔案
將requirements.txt內的torch相關套件都mark掉
用uv pip install -r requirements.txt將套件再安裝一次
:::

---


# **目標四：安裝OpenWEBUI**

先用uv創建OpenWEBUI環境
```
uv init --python 3.12 OpenWEBUI
```

:::success
雖然OpenWEBUI要求用python 3.11，但為了ROCm套件能正常運作，還是用3.12版
:::


安裝ROCm pyTorch套件
```
新方法 ROCm 7.10
uv pip install --pre torch torchvision torchaudio --index-url https://rocm.nightlies.amd.com/v2/gfx1151/

--index-url 後方的URL請依照型號自行替換

(RX 7000 series)        https://rocm.nightlies.amd.com/v2/gfx110X-dgpu/
(Strix Halo / Ryzen AI) https://rocm.nightlies.amd.com/v2/gfx1151/
(RX 9000 series)        https://rocm.nightlies.amd.com/v2/gfx120X-all/ 

舊方法 ROCm 6.44
uv pip install --no-cache-dir https://repo.radeon.com/rocm/windows/rocm-rel-6.4.4/torch-2.8.0a0%2Bgitfc14c65-cp312-cp312-win_amd64.whl
uv pip install --no-cache-dir https://repo.radeon.com/rocm/windows/rocm-rel-6.4.4/torchaudio-2.6.0a0%2B1a8f621-cp312-cp312-win_amd64.whl
uv pip install --no-cache-dir https://repo.radeon.com/rocm/windows/rocm-rel-6.4.4/torchvision-0.24.0a0%2Bc85f008-cp312-cp312-win_amd64.whl
```

安裝OpenWEBUI套件
```
uv pip install open-webui
```

檢查Torch套件版本，沒問題就開啟OpenWEBUI
```
uv pip list

uv run open-webui serve
```

跑完一大串初始設定內容後會出現這畫面
![image](https://hackmd.io/_uploads/SJVPfP46xe.png)

開啟瀏覽器輸入http://localhost:8080 點選開始，就能看到管理者帳號設定畫面了
![image](https://hackmd.io/_uploads/SkjJQvN6le.png)


---

> [name=小輔]
有這幾個套件應該就非常多東西可以玩了，目前程式小白的我還在研究中...
python環境管理目前自己覺得uv很好用，只是有時候會出現奇怪的狀況，要資料夾砍掉重建
