通过fastapi多卡部署codellama-13b-instruct模型

# 如果通过多卡去部署13b会发现两个卡会占用两个进程 rank=0 rank=1,这种情况 会导致程序死掉,所以无法直接部署

class Config(BaseModel):
      prompts: List[str]=["""\
                import socket

                def ping_exponential_backoff(host: str):"""]
      max_gen_len: Optional[int] = None
      temperature: float = 0.2
      top_p: float = 0.90

if dist.get_rank() == 0:
    @app.post("/llama/")
    def generate(config: Config):
          prompts = [config.prompts[0]]
          print(prompts)
          max_gen_len = config.max_gen_len
          temperature = config.temperature
          top_p = config.top_p
          dist.broadcast_object_list([config.prompts, config.max_gen_len,         
                                     config.temperature, config.top_p])
          #print(instructions,max_gen_len,temperature,top_p)
          results = generator.text_completion(
                prompts,  # type: ignore
                max_gen_len=max_gen_len,
                temperature=temperature,
                top_p=top_p,
            )
          print(results)
          return {"responses": results}
        
      uvicorn.run(app, host="127.0.0.1", port=5000)
else:
     while True:
         config = [None] * 4
         try:
             dist.broadcast_object_list(config)
             generator.text_completion(
                    config[0], max_gen_len=config[1], temperature=config[2], 
                    top_p=config[3]
                  )
         except:
                pass

通过判断rank进行部署,这样就不会报错了^_^

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值