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

设置也无法指定gpu,是否在ModelScope模型内部修改代码?

"device = torch.device('cuda:2')
with torch.cuda.device(device):
rex_uninlu_base = pipeline(
task=config['task'],
model=config['model'],
model_revision=config['model_revision'],
)
设置也无法指定gpu,是否在ModelScope模型内部修改代码?"

展开
收起
Lucidly 2024-03-26 22:26:49 24 0
2 条回答
写回答
取消 提交回答
  • 您在pipeline初始化后推理之前加一行rex_uninlu_base.device = torch.device('cuda:2') 此回答整理自钉群“魔搭ModelScope开发者联盟群 ①”

    2024-03-27 12:25:11
    赞同 展开评论 打赏
  • 阿里云大降价~

    在ModelScope中,可以通过设置环境变CUDA_VISIBLE_DEVICES`来指定使用的GPU设备。例如,如果您想使用第2个GPU(索引为1),可以在启动Web UI之前执行以下命令:

    export CUDA_VISIBLE_DEVICES=1
    `da.current_device()`来获取当前使用的GPU设备。例如:
    
    ```python
    import torch
    
    # 获取当前使用的GPU设备
    current_device = torch.cuda.current_device()
    print("Current device:", current_device)
    
    # 使用指定的GPU设备
    device = torch.device(f'cuda:{current_device}')
    with torch.cuda.device(device):
        rex_uninlu_base = pipeline(
            task=config['task'],
            model=config['model'],
            model_revision=config['model_revision'],
        )
    

    这样,您就可以在ModelScope中指定使用的GPU设备了。

    2024-03-27 08:48:21
    赞同 展开评论 打赏

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

相关电子书

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