You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ray远程调用忽略函数参数问题求助

Ray并行Transformer Pipeline参数被忽略的解决方案

问题根源

  1. HuggingFace Pipeline参数传递方式错误:facebook/bart-large-cnn对应的文本摘要任务中,max_length、min_length、do_sample这类生成控制参数需要以关键字参数传递,直接传位置参数会被pipeline内部判定为无效输入而忽略,这就是控制台输出"Ignoring args"的核心原因。
  2. Ray对象存储使用错误:你用ray.put()存入的是字符串而非实际初始化好的pipeline实例,导致远程函数无法执行有效推理。

修正步骤及代码示例

1. 正确初始化并存储Pipeline实例

先完成HuggingFace文本摘要pipeline的初始化,再将实例存入Ray对象存储:

import ray
from transformers import pipeline

# 初始化Ray集群
ray.init(num_cpus=num_cpus, ignore_reinit_error=True)

# 初始化bart-large-cnn摘要pipeline
summarize_pipe = pipeline("summarization", model="facebook/bart-large-cnn")
# 将pipeline实例存入Ray对象存储,供远程函数调用
pipe_ref = ray.put(summarize_pipe)

2. 修正远程函数的参数传递逻辑

在predict函数中,将生成参数以关键字形式传递给pipeline:

@ray.remote
def predict(pipeline_ref, text_data, max_length, min_length, do_sample):
    # 以关键字参数传递生成配置,避免被忽略
    return pipeline_ref(text_data, max_length=max_length, min_length=min_length, do_sample=do_sample)

3. 正确调用远程函数

保持参数传递的一致性,确保生成参数的关键字匹配:

# 假设section是待摘要的文本,some_length是自定义的长度值
predictions = ray.get(predict.remote(pipe_ref, section, max_length=some_length, min_length=some_length, do_sample=False))

补充说明

控制台的"Ignoring args"提示来自HuggingFace Transformers库的pipeline内部逻辑,当检测到未被当前任务支持的位置参数时会触发。对于文本摘要这类生成任务,所有控制生成行为的参数都必须以关键字参数传递,否则会被判定为无效输入而忽略。

内容的提问来源于stack exchange,提问作者SamAct

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 18:16:04