更新时间:2024-08-20 GMT+08:00
分享

在MaaS中创建模型

在模型广场选择模型后,需要使用模型创建一个自定义模型,才能进行模型训练、推理。

场景描述

基于ModelArts Studio大模型即服务平台在模型广场预置的模型模板,用户可以使用推荐的模型权重文件或自定义的模型权重文件,创建一个自己的模型。其中,推荐模型权重文件的获取请参见表1

创建成功的模型可以在ModelArts Studio大模型即服务平台进行调优、压缩、推理等操作。

表1 推荐的模型权重文件获取地址

模型名称

推荐模型权重与词表文件获取地址

chatglm3-6b

obs://maas-operations/preset_models_6.3.906/chatglm3-6b

glm4-9b

obs://maas-operations/preset_models_6.3.906/glm-4-9b-chat

Baichuan2-13B

obs://maas-operations/preset_models_6.3.906/Baichuan2-13B-Chat

Llama2-13b

obs://maas-operations/preset_models_6.3.906/Llama-2-13b-chat-hf

Llama2-13B-AWQ

obs://maas-operations/preset_models_6.3.906/Llama-2-13B-chat-AWQ

Llama2-70B-AWQ

obs://maas-operations/preset_models_6.3.906/Llama-2-70B-Chat-AWQ

Llama2-7b

obs://maas-operations/preset_models_6.3.906/Llama-2-7b-chat-hf

Llama2-7B-AWQ

obs://maas-operations/preset_models_6.3.906/Llama-2-7B-Chat-AWQ

Llama3.1-8B

obs://maas-operations/preset_models_6.3.906/Meta-Llama-3.1-8B

Llama3.1-8B

obs://maas-operations/preset_models_6.3.906/Meta-Llama-3.1-8B-Instruct

Llama3-70b-awq

obs://maas-operations/preset_models_6.3.906/llama-3-70b-instruct-awq

Llama3-8B

obs://maas-operations/preset_models_6.3.906/Meta-Llama-3-8B-Instruct

Llama3-8b-awq

obs://maas-operations/preset_models_6.3.906/llama-3-8b-instruct-awq

Qwen1.5-14B

obs://maas-operations/preset_models_6.3.906/Qwen1.5-14B-Chat

Qwen1.5-14B-AWQ

obs://maas-operations/preset_models_6.3.906/Qwen1.5-14B-Chat-AWQ

Qwen1.5-32B

obs://maas-operations/preset_models_6.3.906/Qwen1.5-32B-Chat

Qwen1.5-72B-AWQ

obs://maas-operations/preset_models_6.3.906/Qwen1.5-72B-Chat-AWQ

Qwen1.5-7B

obs://maas-operations/preset_models_6.3.906/Qwen1.5-7B-Chat

Qwen1.5-7B-AWQ

obs://maas-operations/preset_models_6.3.906/Qwen1.5-7B-Chat-AWQ

Qwen-14B

obs://maas-operations/preset_models_6.3.906/Qwen-14B-Chat

Qwen2-0.5B

obs://maas-operations/preset_models_6.3.906/Qwen2-0.5B-Instruct

Qwen2-1.5B

obs://maas-operations/preset_models_6.3.906/Qwen2-1.5B-Instruct

Qwen2-72B-AWQ

obs://maas-operations/preset_models_6.3.906/Qwen2-72B-Instruct-AWQ

Qwen2-7B

obs://maas-operations/preset_models_6.3.906/Qwen2-7B-Instruct

Qwen2-7B-AWQ

obs://maas-operations/preset_models_6.3.906/Qwen2-7B-Instruct-AWQ

Qwen-7B

obs://maas-operations/preset_models_6.3.906/Qwen-7B-Chat

Yi-34B

obs://maas-operations/preset_models_6.3.906/Yi-34B-Chat

Yi-6B

obs://maas-operations/preset_models_6.3.906/Yi-6B-Chat

约束限制

  • 用于生成专属模型的模型权重文件需要满足Hugging Face上的对应模型的文件格式要求。
    • 模型权重文件夹下包括权重类文件、词表类文件和配置类文件。
    • 可以使用transformers的from_pretrained方法对模型权重文件夹进行加载。

    具体请参见Hugging Face官方文档Documentations

  • 当选择ChatGLM3-6B、GLM-4-9B、Qwen-7B、Qwen-14B和Qwen-72B模型框架时,需要修改权重配置才能正常运行模型,操作步骤请参见修改权重配置

前提条件

已准备好用于生成专属模型的模型权重文件,并存放于OBS桶中,OBS桶必须和MaaS服务在同一个Region下。当使用推荐的模型权重文件时,需要从表1中下载对应的模型权重文件,存放到OBS桶中。

修改权重配置

当选择ChatGLM3-6B、GLM-4-9B、Qwen-7B、Qwen-14B和Qwen-72B模型框架创建模型时,如果使用自定义模型权重文件,则需要修改权重配置才能正常运行模型;如果使用推荐的模型权重文件,则不需要修改权重配置,可以跳过该步骤。修改后的权重文件要更新至OBS桶中。

  • ChatGLM3-6B、GLM-4-9B

    修改文件“tokenization_chatglm.py”

    • 第一处

      原内容

      # Load from model defaults assert self.padding_side == "left"

      修改为

      # Load from model defaults # assert self.padding_side == "left"
    • 第二处

      原内容

      if needs_to_be_padded:    
      difference = max_length - len(required_input)     
      if "attention_mask" in encoded_inputs:         
      encoded_inputs["attention_mask"] = [0] * difference + encoded_inputs["attention_mask"]    
      if "position_ids" in encoded_inputs:        
      encoded_inputs["position_ids"] = [0] * difference + encoded_inputs["position_ids"]    encoded_inputs[self.model_input_names[0]] = [self.pad_token_id] * difference + required_input

      修改为

      if needs_to_be_padded:    
      difference = max_length - len(required_input)     
      if "attention_mask" in encoded_inputs:         
      encoded_inputs["attention_mask"] = encoded_inputs["attention_mask"] + [0] * difference     
      if "position_ids" in encoded_inputs:        
      encoded_inputs["position_ids"] = encoded_inputs["position_ids"] + [0] * difference     encoded_inputs[self.model_input_names[0]] =  required_input + [self.pad_token_id] * difference
  • Qwen-7B、Qwen-14B和Qwen-72B

    修改文件“modeling_qwen.py”

    原内容

    SUPPORT_BF16 = SUPPORT_CUDA and torch.cuda.is_bf16_supported() SUPPORT_FP16 = SUPPORT_CUDA and torch.cuda.get_device_capability(0)[0] >= 7

    修改为

    SUPPORT_BF16 = SUPPORT_CUDA and True SUPPORT_FP16 = SUPPORT_CUDA and True

创建我的模型

  1. 登录ModelArts管理控制台。
  2. 在左侧导航栏中,选择“ModelArts Studio”进入ModelArts Studio大模型即服务平台。
  3. 进入创建模型页面。
    • 方式一:在ModelArts Studio左侧导航栏中,选择“我的模型”进入模型列表,单击“创建模型”弹出创建模型页面。
    • 方式二:在ModelArts Studio左侧导航栏中,选择“模型广场”,在模型广场选择模型并单击“立即使用”进入模型详情页,单击“自定义模型”弹出创建模型页面。
  4. 在创建模型页面,配置参数。
    表2 创建模型

    参数

    说明

    来源模型

    • 当从“我的模型”进入创建模型页面时,单击选择基础模型完成模型选择。
    • 当从“模型广场”进入创建模型页面时,此处默认呈现选择的模型。

    当选择模型后,支持单击“重新选择”更改模型。

    模型名称

    自定义模型名称。

    支持1~64位,以中文、大小写字母开头,只包含中文、大小写字母、数字、下划线(_)、中划线(-)和(.)。

    描述

    模型简介。支持100字符。

    权重设置与词表

    默认选择自定义权重,不支持修改。

    选择自定义权重路径

    选择存放模型权重文件与词表的OBS路径,必须选择到模型文件夹。

    权重文件必须满足约束限制

  5. 参数配置完成后,单击“确定”,创建自定义模型。

    在模型列表,当模型“状态”变成“创建成功”时,表示模型创建完成。

查看我的模型详情

  1. 登录ModelArts管理控制台。
  2. 在左侧导航栏中,选择“ModelArts Studio”进入ModelArts Studio大模型即服务平台。
  3. 在ModelArts Studio左侧导航栏中,选择“我的模型”进入模型列表。
  4. 单击模型名称,进入模型详情页面,可以查看模型“基本信息”“作业记录”
    • 基本信息:可以查看模型名称、ID、来源模型等信息。
    • 作业记录:可以查看该模型被用于哪些作业类型,以及当前作业的状态等信息。

删除我的模型

删除操作无法恢复,请谨慎操作。

  1. 登录ModelArts管理控制台。
  2. 在左侧导航栏中,选择“ModelArts Studio”进入ModelArts Studio大模型即服务平台。
  3. 在ModelArts Studio左侧导航栏中,选择“我的模型”进入模型列表。
  4. 在模型列表,单击模型名称,进入模型详情页面,查看模型的“作业记录”
    • 如果作业记录为空,则直接执行下一步。
    • 如果作业记录存在作业,则先删除所有作业,再执行下一步。

    当模型存在作业记录会删除失败。

  5. 在模型详情页,单击右上角的“删除”,在弹窗中输入“DELETE”,单击“确定”,删除模型。

相关文档