MOSS icon indicating copy to clipboard operation
MOSS copied to clipboard

INT8量化版本在设置加载显卡时运行报错:Triton Error [CUDA]: an illegal memory access was encountered

Open Ratuchetp opened this issue 2 years ago • 2 comments

我在多卡机器上部署moss-moon-003-sft-int8模型,运行下面指令是:

model = AutoModelForCausalLM.from_pretrained("fnlp/moss-moon-003-sft-int8", trust_remote_code=True).half().cuda(1)
inputs="blabla"
for k in inputs:
   inputs[k] = inputs[k].cuda(1)

outputs = model.generate(**inputs, do_sample=True, temperature=0.7, top_p=0.8, repetition_penalty=1.02, max_new_tokens=256)

处报错Triton Error [CUDA]: an illegal memory access was encountered 令人困惑的是,将上端代码中的cuda(1)替换为cuda(),错误消失,但模型将自动加载在0号显卡上。 另外,将模型替换为fnlp/moss-moon-003-sft错误消失,模型能够正确加载在1号显卡上并输出outputs。

Ratuchetp avatar Apr 25 '23 11:04 Ratuchetp

我遇到相似的问题,但不完全相同。 在使用 int8 和 int4 推理时,无法双显卡同时使用 (是指一张显卡显存溢出时,另一张显卡没有调用起来);但原始模型 (fnlp/moss-moon-003-sft) 是正常的。 是否基于 triton 的低精度模型量化的版本都不适合使用多显卡呀?

ajz34 avatar Apr 25 '23 12:04 ajz34

@Ratuchetp @ajz34 Hi 目前量化版本模型仅支持单卡部署。请不要使用model.half().cuda(1)或者inputs[k].cuda(1),而是CUDA_VISIBLE_DEVICES=1 python xxx.py,在python代码里使用model.half().cuda()inputs[k].cuda()

txsun1997 avatar Apr 25 '23 14:04 txsun1997

@txsun1997 非常感谢您的解答

我这边想要做是将两个int8模型加载到两张显卡上做并行推理,代码中需要设置两个模型的具体加载位置。个人理解的话,更像是把两个模型分别去做单卡部署,如果通过修改环境变量设置部署位置,可能会存在多个程序相互影响的情况。

Anyway,期待后续版本的迭代优化!

Ratuchetp avatar Apr 26 '23 02:04 Ratuchetp

我试过把非量化版本的pytorch_model.bin.index.json修改一下,然后放在量化版本目录下,然后用多卡的代码执行就可以。

boystray avatar May 28 '23 13:05 boystray