开发者社区 > ModelScope模型即服务 > 正文

modelscope中,没有device参数了,无法使用gpu怎么解决?

"用训练后的结果进行数据处理的时候 提示错误:
/opt/miniconda3/envs/mt5text38/lib/python3.8/site-packages/transformers/modeling_utils.py:962: FutureWarning: The device argument is deprecated and will be removed in v5 of Transformers.
warnings.warn(
/opt/miniconda3/envs/mt5text38/lib/python3.8/site-packages/transformers/generation/utils.py:1178: UserWarning: Using the model-agnostic default max_length (=20) to control the generation length. We recommend setting max_new_tokens to control the maximum length of the generation.
warnings.warn(
/opt/miniconda3/envs/mt5text38/lib/python3.8/site-packages/transformers/modeling_utils.py:916: FutureWarning: The device argument is deprecated and will be removed in v5 of Transformers.
modelscope中,没有device参数了,无法使用gpu怎么解决?"

展开
收起
Lucidly 2024-03-18 20:32:03 86 0
3 条回答
写回答
取消 提交回答
  • 对于第一条错误信息,它提示在Transformers库v5版本中将移除device参数。在ModelScope(魔搭)中,若无法指定GPU设备,您可以尝试通过设置环境变量CUDA_VISIBLE_DEVICES来指定使用的GPU,或者确保您的代码中正确设置了模型加载和运算时的设备上下文,例如使用torch.device("cuda")device="cuda"(如果存在GPU资源)。

    2024-03-19 16:05:50
    赞同 展开评论 打赏
  • 在 transformers 库中,您收到的警告信息是关于 device 参数即将在 v5 版本中移除,推荐通过设置 max_new_tokens 来控制生成文本的最大长度。对于 ModelScope 中无法指定设备(GPU)的问题,通常情况下,您可以直接将模型和数据加载到 GPU 上,例如:

    import torch
    
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    model.to(device)
    
    2024-03-19 11:07:02
    赞同 展开评论 打赏
  • "https://modelscope.cn/docs/%E8%AE%AD%E7%BB%83%E7%9A%84%E8%AF%A6%E7%BB%86%E5%8F%82%E6%95%B0 70197e257b79ae869404607bd890ad01.png
    此回答整理自钉群“魔搭ModelScope开发者联盟群 ①”"

    2024-03-18 21:02:05
    赞同 1 展开评论 打赏

ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!

相关电子书

更多
DeepStream: GPU加速海量视频数据智能处理 立即下载
阿里巴巴高性能GPU架构与应用 立即下载
GPU在超大规模深度学习中的发展和应用 立即下载