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

在AWS SageMaker部署Falcon LLM时遇权重转换错误,求解决方案

解决AWS SageMaker部署Falcon LLM时的权重下载转换错误

问题复现

在AWS SageMaker通过HuggingFace官方部署代码部署Falcon LLM模型时,出现权重下载转换失败,错误日志如下:

#033[2m2023-07-31T06:58:11.298494Z#033[0m #033[31mERROR#033[0m #033[2mtext_generation_launcher#033[0m#033[2m:#033[0m Download encountered an error: Traceback (most recent call last):
  File "/opt/conda/bin/text-generation-server", line 8, in <module>
    sys.exit(app())
  File "/opt/conda/lib/python3.9/site-packages/text_generation_server/cli.py", line 151, in download_weights
    utils.convert_files(local_pt_files, local_st_files)
  File "/opt/conda/lib/python3.9/site-packages/text_generation_server/utils/convert.py", line 84, in convert_files
    convert_file(pt_file, sf_file)
  File "/opt/conda/lib/python3.9/site-packages/text_generation_server/utils/convert.py", line 62, in convert_file
    save_file(pt_state, str(sf_file), metadata={
    "format": "pt"
})
  File "/opt/conda/lib/python3.9/site-packages/safetensors/torch.py", line 232, in save_file
    serialize_file(_flatten(tensors), filename, metadata=metadata)

解决方案

1. 锁定兼容的safetensors版本

错误发生在safetensors序列化环节,版本不兼容是常见诱因。在部署依赖中指定稳定兼容版本:

  • 在requirements.txt中添加:
    safetensors==0.3.1
    
  • 在SageMaker Estimator配置中关联该依赖文件:
    from sagemaker.huggingface import HuggingFace
    
    estimator = HuggingFace(
        entry_point="inference.py",
        requirements_file="requirements.txt",
        # 其他实例配置...
    )
    

2. 提前预下载并上传权重到S3

避免部署时在线下载权重出现中断或损坏:

  • 使用huggingface-cli下载完整权重到本地:
    huggingface-cli download tiiuae/falcon-7b --local-dir ./falcon-7b --local-dir-use-symlinks False
    
  • 将本地权重上传到AWS S3桶,部署时直接指定S3路径作为model_id:
    estimator = HuggingFace(
        model_data="s3://your-bucket/path/to/falcon-7b",
        # 其他实例配置...
    )
    

3. 调整实例资源与权限

  • 资源配置:选择内存充足的实例类型(如ml.g5.2xlarge及以上),避免内存不足导致转换失败。
  • 权限配置:确保SageMaker执行角色拥有:
    • S3桶的读写权限(s3:GetObject、s3:PutObject)
    • 访问HuggingFace Hub的权限(若使用在线下载方式)

4. 跳过自动转换,直接使用safetensors格式权重

部分Falcon模型已提供原生safetensors权重,部署时直接启用:

  • 在启动命令中添加--trust-remote-code参数,允许加载模型自定义代码:
    text-generation-launcher --model-id tiiuae/falcon-7b --trust-remote-code --port 8080
    
  • 或在SageMaker环境变量中设置:
    estimator = HuggingFace(
        environment={"TRUST_REMOTE_CODE": "true"},
        # 其他实例配置...
    )
    

5. 修复容器文件系统权限

确保容器内有权限写入转换后的权重文件:

  • 在Dockerfile中添加权限设置:
    RUN chmod -R 777 /opt/ml/model
    

内容的提问来源于stack exchange,提问作者Chandanraj C L

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 10:03:17