1
6
1
运行时
Triton报错问题
2025-10-20 14:58:09
165
triton-3.0.0+das.opt1.dtk25041-cp311-cp311-manylinux_2_28_x86_64.whl,使用以上文件安装了Triton,在运行sd模型推理时发生了如图报错RuntimeError: Cannot find a working triton installation.,我的本地环境是dtk25.04.1+pytorch2.4.1(2.5.1也试过 同样的问题),求教如何解决,以及我如何能用Triton库完成模型的推理加速? ![attachmentId-image.png](/api-forum/file/Redirect?path=forum/yxh/1760943431946/image.png)
全部评论(7)
只看楼主
Z
zhufzh1
1楼
您好,麻烦提供下使用的DCU型号,详细报错日志,pip list 输出的库列表以及推理所用到的脚本代码方便我们帮助您排查。初步来看可能是您那边使用了torch.compile之类的编译优化触发了Inductor 后端,但Inductor没找到Triton库。可以pip list先确认下triton是否成功安装了
2025/10/20
网
网友8Q6Ddr
回复 @zhufzh1
DCU型号BW1000,确认过triton已经安装,版本号:3.0.0+das.opt1.dtk25041,您说的对我用了torch.compile库,下面是我的测试脚本: import torch from diffusers import StableDiffusionPipeline, EulerAncestralDiscreteScheduler import time import os import pandas as pd MODEL_ID = "/opt/model/stablediffusion/model" DATASET_PATH = "/opt/datasets/pokemon-blip-captions/train.csv" PROMPT_COLUMN = "text" SCHEDULER_CLASS = EulerAncestralDiscreteScheduler NUM_STEPS = 50 WIDTH = 768 HEIGHT = 768 BATCH_SIZE = 2 # 单批数量:2 TOTAL_BATCHES = 10 # 总批次数:10 PRECISION = torch.float16 OUTPUT_DIR = "local_model_generated_images" if not os.path.exists(OUTPUT_DIR): os.makedirs(OUTPUT_DIR) print(f"生成的图像将保存在: ./{OUTPUT_DIR}/ 目录中") try: df = pd.read_csv(DATASET_PATH) all_prompts = df[PROMPT_COLUMN].tolist() print(f"成功加载 {len(all_prompts)} 条提示词。") except Exception as e: exit() print(f"正在从本地路径 {MODEL_ID} 加载模型...") print(f"使用采样器: {SCHEDULER_CLASS.__name__}") print(f"使用数据精度: {PRECISION}") try: scheduler = SCHEDULER_CLASS.from_pretrained(MODEL_ID, subfolder="scheduler") except Exception as e: scheduler = SCHEDULER_CLASS.from_pretrained("stabilityai/stable-diffusion-2-1", subfolder="scheduler") pipe = StableDiffusionPipeline.from_pretrained( MODEL_ID, scheduler=scheduler, torch_dtype=PRECISION, safety_checker=None ) pipe = pipe.to("cuda") pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True) # --- 4. Warmup --- _ = pipe( prompt=all_prompts[0], num_inference_steps=5, width=WIDTH, height=HEIGHT, batch_size=1, output_type="latent" ) print("\n" + "="*50) print(f"开始正式测试: {TOTAL_BATCHES} 个批次, 每批 {BATCH_SIZE} 张图") print(f"使用来自 {DATASET_PATH} 的提示词") print("="*50) start_time = time.time() for i in range(TOTAL_BATCHES): print(f" batch {i+1}/{TOTAL_BATCHES} ...") current_prompts = [] for j in range(BATCH_SIZE): prompt_index = (i * BATCH_SIZE + j) % len(all_prompts) current_prompts.append(all_prompts[prompt_index]) images = pipe( prompt=current_prompts, num_inference_steps=NUM_STEPS, width=WIDTH, height=HEIGHT, output_type="pil" ).images print(f" ...正在保存 {len(images)} 张图像到 {OUTPUT_DIR}/ ...") for j, img in enumerate(images): image_filename = f"batch_{i+1}_image_{j}.png" save_path = os.path.join(OUTPUT_DIR, image_filename) img.save(save_path) torch.cuda.synchronize() end_time = time.time() total_time = end_time - start_time total_images = TOTAL_BATCHES * BATCH_SIZE latency_per_image = total_time / total_images throughput_images_per_sec = total_images / total_time print("\n" + "="*50) print(" 本地模型 性能测试报告") print("="*50) print(f" 测试硬件: 海光DCU (PyTorch 2.4 + ROCm)") print(f" 加速框架: torch.compile()") print("---") print(f" 模型: {MODEL_ID} (本地)") print(f" 提示词来源: {DATASET_PATH}") print(f" 采样器: {SCHEDULER_CLASS.__name__} (Euler a)") print(f" 精度: {PRECISION}") print(f" 分辨率: {WIDTH}x{HEIGHT}") print(f" 推理步数: {NUM_STEPS}") print("---") print(f" 总批次数: {TOTAL_BATCHES}") print(f" 单批数量: {BATCH_SIZE}") print(f" 生成图片总数: {total_images} 张") print(f" 总耗时: {total_time:.2f} 秒") print("---") print(f" 性能指标 (延迟): {latency_per_image:.2f} 秒/每张图") print(f" 性能指标 (吞吐量): {throughput_images_per_sec:.2f} 张图/每秒") print("="*50)
2025/10/21
网
网友8Q6Ddr
回复 @zhufzh1
图片是他报错的全部日志,刚重新跑的一遍,和帖子的信息不太一致但估计也是这个Triton库的问题,辛苦您看下
2025/10/21
Z
zhufzh1
回复 @网友8Q6Ddr
在相同DCU,dtk,torch,triton,python环境下试了下,我这边是可以直接跑通的(docker环境)。这里从截图观察到您应该是使用conda来搭的环境。推测可能还是triton安装的方式造成的报错(是在conda环境里面还是外面pip install的轮子)可以pip show triton看下triton是安装到的系统目录(/usr/local/...)下还是conda环境下(/yours/conda/env/lib/...)之后export PYTHONPATH= 查找到的triton目录的父目录,然后执行您的SD2.1推理脚本试试能否解决问题
2025/10/21
全部6条回复
没有更多内容了
--
楼主
Level.2
0 帖子
楼主热帖
暂无数据