2025/12/26

GB10 : MXFP4 support in transformers

在用 huggingfacetransformers load gpt-oss:120b 來 run,出現
triton.runtime.errors.PTXASError: PTXAS error: Internal Triton PTX codegen error
`ptxas` stderr:
ptxas fatal   : Value 'sm_121a' is not defined for option 'gpu-name'
transformers calling 順序
gpt-oss-120b (uses MXFP4 quantization)
    ↓
transformers (loads model)
    ↓
kernels package (provides MXFP4 Triton kernels)
    ↓
Triton (compiles GPU kernels at runtime)
    ↓
ptxas (NVIDIA's PTX assembler, bundled with Triton)
    ↓
❌ Doesn't recognize sm_121a (Blackwell)
然後 ptxas fatal : Value 'sm_121a' is not defined for option 'gpu-name' 說:
The issue should be fixed by using PTXAS shipped with CUDA 13. Try setting TRITON_PTXAS_PATH to /usr/local/cuda/bin/ptxas etc.
所以看 python 自己的 triton ptxas 版本:
$ ./lib/python3.12/site-packages/triton/backends/nvidia/bin/ptxas --version
ptxas: NVIDIA (R) Ptx optimizing assembler
Copyright (c) 2005-2025 NVIDIA Corporation
Built on Fri_Feb_21_20:22:20_PST_2025
Cuda compilation tools, release 12.8, V12.8.93
Build cuda_12.8.r12.8/compiler.35583870_0
系統的:
$ ptxas --version
ptxas: NVIDIA (R) Ptx optimizing assembler
Copyright (c) 2005-2025 NVIDIA Corporation
Built on Wed_Aug_20_01:53:56_PM_PDT_2025
Cuda compilation tools, release 13.0, V13.0.88
Build cuda_13.0.r13.0/compiler.36424714_0
所以依照說明宣告PATH 之後,GB10 就可以用 transformers正常的支援 gpt-oss:120b 的 MXFP4 了。
export TRITON_PTXAS_PATH=/usr/local/cuda/bin/ptxas

有關 gpt-oss:120b 與 MXFP4 可以看 :MXFP4
要等 Pypl 的 triton 用 cuda13 重build 之後,package 才算 official support.

DGX Spark (GB10), transformers load gpt-oss:120b 時遇到的問題

 

問題 1:缺少 Python 開發標頭檔

編譯錯誤
根本原因
Triton 在執行時需要編譯 CUDA 工具模組,但系統缺少 Python 開發標頭檔 (Python.h)。
解決方案
已修復 安裝 Python 開發套件:
sudo apt install python3-dev

問題 2:ptxas 不支援 Blackwell 架構 (sm_121a)

GPU 相容性
錯誤訊息
ptxas fatal : Value 'sm_121a' is not defined for option 'gpu-name'
根本原因

Triton 套件內建的 ptxas (PTX 組譯器) 版本太舊,不認識最新的 Blackwell GPU 架構代號 sm_121a

相關 GitHub Issue: triton-lang/triton#8539

解決方案
已修復 使用系統安裝的較新版 ptxas (CUDA 13.0 內建):
export TRITON_PTXAS_PATH=/usr/local/cuda/bin/ptxas
python llmchat.py
或使用啟動腳本 run_chat.sh 自動設定此環境變數。

問題 3:Tensor on device meta 錯誤

記憶體配置
錯誤訊息
RuntimeError: Tensor on device meta is not on the expected device cuda:0!
根本原因

當使用 device_map="auto" 載入大型模型時,accelerate 套件會使用「meta device」作為權重的佔位符號,延遲載入實際資料。

在 MXFP4 量化與 DGX Spark 的組合下,部分權重 (特別是 MoE router) 可能未能正確從 meta device 轉移到 CUDA device,導致運算失敗。

解決方案
已修復 修改模型載入參數,避免使用延遲載入:
self.model = AutoModelForCausalLM.from_pretrained(
    self.model_id,
    torch_dtype=torch.bfloat16,    # 使用明確的資料型別
    device_map="auto",
    low_cpu_mem_usage=False,       # 停用延遲載入
)

2025/12/6

pyenv + venv

 因為 venv 只負責隔離環境(pip install 到 local),沒有管理python 版本的功能,所以用 pyenv 來做。

pyenv 會 create 一個 ~/.pyenv 目錄,所有你需要的 python 版本,然後就可以用 pyenv local 來決定這個位置(folder) 要使用那一個版本。

這樣配合 venv 就可以作到 python 版本管理和 package 隔離。

所以安裝 pyenv 要修改 PATH,讓pyenv/bin/python 優先被執行,才能發揮效果。

pyenv 目前沒有進入 apt repo,所以要自己下載安裝。修改 .bashrc.

2025/11/29

ComfyUI Stable Diffusion Service Setup

   This guide assumes you have Python 3.8+ and NVIDIA GPU drivers (CUDA 13.0 or compatible) installed on your system.


   1. Navigate to your desired project directory:

      Open your terminal and change to the directory where you want to install ComfyUI. If the directory doesn't exist, create it.


   1     cd /path/to/your/comfyui_project

   2     # If the directory is empty or you want a fresh start, ensure it is empty

   3     # If .venv exists, remove it: rm -rf .venv


   2. Clone the ComfyUI repository:

      This will download all the necessary ComfyUI files into your current directory.

   1     git clone https://github.com/comfyanonymous/ComfyUI.git .


   3. Create a Python Virtual Environment:

      We'll use uv to create an isolated environment for ComfyUI's dependencies.

   1     uv venv


   4. Install PyTorch with CUDA Support:

      This step is crucial for GPU acceleration. We'll use the specific PyTorch build that is compatible with your DGX Spark's CUDA environment (cu129 index).


   1     uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu129


   5. Install ComfyUI's remaining dependencies:

   1     uv pip install -r requirements.txt


   6. Download the Stable Diffusion Model:

      You need a Stable Diffusion model checkpoint. We'll download the v1-5-pruned-emaonly.safetensors model, which is a standard choice.

      First, ensure the target directory exists:


   1     mkdir -p models/checkpoints

      Then, download the model:


   1     wget -O models/checkpoints/v1-5-pruned-emaonly.safetensors https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors


   7. Launch the ComfyUI Server:

      To make ComfyUI accessible over your network (for tools like Open-WebUI), launch it with the --listen flag. You can run it in the foreground to see output or in the background:


       * To run in foreground (for debugging/monitoring):

   1         .venv/bin/python main.py --listen

          (You'll need to press Ctrl+C to stop it.)


       * To run in background (recommended for service):

   1         nohup .venv/bin/python main.py --listen > comfyui.log 2>&1 &

          This command runs ComfyUI in the background, redirects its output to comfyui.log, and detaches it from your terminal. You can check tail -f comfyui.log for logs or use fg to

  bring it back to foreground if launched using &.


   8. Verify ComfyUI is Running:

      Open your web browser and go to http://<YOUR_SPARK_IP>:8188. Replace <YOUR_SPARK_IP> with the actual IP address of your machine. If you see the ComfyUI interface, the server is

  running.


   9. Test Image Generation:

      Inside the ComfyUI web UI, try to generate a simple image using the default workflow. If it successfully generates an image, your Stable Diffusion service is fully operational.


   10. Connect to Open-WebUI:

      You can now configure Open-WebUI to use this ComfyUI instance by pointing its "API URL" setting to http://<YOUR_SPARK_IP>:8188.


2025/11/25

在 Ubuntu 用 Miniforge 建立 PyTorch CUDA 環境

Ubuntu 24.04 上,利用 Miniforge 建立 Python 環境,安裝支援 CUDAPyTorch

特別注意,從 PyTorch 2.6 開始,官方已不再發布 CondaGPU 套件,因此必須改用 pip 搭配 PyTorch 官方提供的 CUDA 套件。


一 安裝 Miniforge

下載最新版 Miniforge 安裝腳本。

wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh

安裝執行檔。

bash Miniforge3-Linux-x86_64.sh

當安裝程式詢問是否要執行 conda init 時,選擇 no,避免修改 .bashrc 或 .profile。

二 啟用 Miniforge 基底環境

要使用 Miniforge 時,在當前 shell 手動載入即可。

source ~/miniforge3/bin/activate

出現 (base) 前綴代表 Miniforge 已啟用。

三 建立獨立的 PyTorch 環境

Python 3.10 建立名為 torch 的環境。

conda create -n torch python=3.10

啟用環境。

conda activate torch

四 移除可能已存在的 CPU 版 PyTorch

由於 Conda 預設可能從 conda-forge 安裝 CPU 版 PyTorch,先將其移除。

conda remove -y pytorch pytorch-cuda torchvision torchaudio

pip uninstall -y torch torchvision torchaudio

五 安裝支援 CUDA 的 PyTorch

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126

六 驗證 CUDA 是否可用

python - <<'EOF'

import torch

print("PyTorch:", torch.__version__)

print("CUDA version:", torch.version.cuda)

print("CUDA available:", torch.cuda.is_available())

if torch.cuda.is_available():

    print("GPU name:", torch.cuda.get_device_name(0))

EOF

若 CUDA available 顯示 True,且顯示 GPU 名稱,代表 GPU 加速已正常啟用。




2025/11/1

 gitdaemon 不支援 lfs,如果要的話,要另外 install 一個 lfs server。