邂逅的光阴 2024-04-29 11:04 采纳率: 0%
浏览 9

python 华为 配置文件

#为什么我的 checkpoint_name_or_path是有值的,却还出现2024-04-29 10:48:31,918 - mindformers[mindformers/models/modeling_utils.py:1437] - INFO - model built, but weights is unloaded, since the config has no checkpoint_name_or_path attribute or checkpoint_name_or_path is None.的情况

seed: 0
run_mode: 'eval'
output_dir: './output' # path to save checkpoint/strategy
load_checkpoint: ''
src_strategy_path_or_dir: ''
auto_trans_ckpt: False  # If true, auto transform load_checkpoint to load in distributed model
only_save_strategy: False
resume_training: False

# context
context:
  mode: 0 #0--Graph Mode; 1--Pynative Mode
  device_target: "Ascend"
  enable_graph_kernel: False
  graph_kernel_flags: "--opt_level=0"
  max_call_depth: 10000
  save_graphs: False
  device_id: 0

# aicc
remote_save_url: "Please input obs url on AICC platform."

# runner
runner_config:
  epochs: 30
  batch_size: 32
  image_size: 224
  sink_mode: False
  sink_size: 2

# parallel
use_parallel: False
parallel:
  parallel_mode: 0 # 0-data parallel, 1-semi-auto parallel, 2-auto parallel, 3-hybrid parallel
  gradients_mean: True
  enable_alltoall: False
  full_batch: False
  search_mode: "sharding_propagation"
  enable_parallel_optimizer: False
  strategy_ckpt_save_file: "./ckpt_strategy.ckpt"
parallel_config:
  data_parallel: 1
  model_parallel: 1
  expert_parallel: 1
  pipeline_stage: 1
  micro_batch_num: 1
  gradient_aggregation_group: 4
micro_batch_interleave_num: 1

# recompute
recompute_config:
  recompute: False
  parallel_optimizer_comm_recompute: False
  mp_comm_recompute: True
  recompute_slice_activation: False

# autotune
auto_tune: False
filepath_prefix: './autotune'
autotune_per_step: 10

# profile
profile: False
profile_start_step: 1
profile_stop_step: 10
init_start_profile: False
profile_communication: False
profile_memory: True

# Trainer
trainer:
  type: ZeroShotImageClassificationTrainer
  model_name: 'clip_vit_b_32'

# eval dataset
eval_dataset:  &eval_dataset
  data_loader:
    type: Cifar100DataLoader
    dataset_dir: 'cifar-100-python'
    column_names: ["image", "text", "label"]
    stage: 'test'
    fine_label: True
    shuffle: False
    hypothesis_template: "a picture of {}"
  tokenizer:
    type: CLIPTokenizer
    pad_token: '!'
  text_transforms:
    type: TokenizerForward
    max_length: 77
    padding: "max_length"
  transforms:
    - type: ToPIL
    - type: Resize
      size: 224
      interpolation: 'linear'
    - type: CenterCrop
      size: 224
    - type: ToTensor
    - type: Normalize
      mean: [0.48145466, 0.4578275, 0.40821073]
      std: [0.26862954, 0.26130258, 0.27577711]
      is_hwc: False
  num_parallel_workers: 8
  python_multiprocessing: False
  drop_remainder: False
  batch_size: 32
  repeat: 1
  numa_enable: False
  prefetch_size: 30
  seed: 2022
eval_dataset_task:
  type: ZeroShotImageClassificationDataset
  dataset_config: *eval_dataset

# model
model:
  arch:
    type: CLIPModel
  model_config:
    type: CLIPConfig
    text_config:
      type: CLIPTextConfig
      vocab_size: 49408
      hidden_size: 512
      intermediate_size: 2048
      num_hidden_layers: 12
      num_attention_heads: 8
      max_position_embeddings: 77
      hidden_act: "quick_gelu"
      attention_dropout: 0.0
      drop_out: 0.0
      initializer_range: 0.02
      initializer_factor: 1.0
    vision_config:
      type: CLIPVisionConfig
      hidden_size: 768
      intermediate_size: 3072
      num_hidden_layers: 12
      num_attention_heads: 12
      image_size: 224
      patch_size: 32
      hidden_act: "quick_gelu"
      dropout: 0.0
      attention_dropout: 0.0
      initializer_range: 0.02
      initializer_factor: 1.0
    dtype: float16  # type of tensors
    checkpoint_name_or_path: clip_vit_b_32   # the loaded model type
    #checkpoint_name_or_path: "/home/ma-user/work/mindformers/output/checkpoint_network/rank_0/mindformers_rank_0_1-network.ckpt"
    projection_dim: 512  # feature dims
    logit_scale_init_value: 2.6592

# lr sechdule
layer_scale: False
layer_decay: 0.65

# optimizer
optimizer:
  type: adamw
  weight_decay: 0.001
  learning_rate: 0.00001
lr_scale: False
lr_scale_factor: 256

# callbacks
callbacks:
  - type: MFLossMonitor
  - type: CheckpointMointor
    prefix: "mindformers"
    save_checkpoint_steps: 100
    integrated_save: True
    async_save: False
  - type: ObsMonitor
eval_callbacks:
  - type: ObsMonitor

# metric
metric:
  type: 'Accuracy'

# processor
processor:
  type: CLIPProcessor
  image_processor:
    type: CLIPImageProcessor
    image_resolution: 224  # input image size
  tokenizer:
    type: CLIPTokenizer
    pad_token: '!' # corresponding token id is 0
top_k: 3
save_file: 'results.txt'
#save_file: '/home/ma-user/work/mindformers/results.txt'


  • 写回答

5条回答 默认 最新

  • 阿里嘎多学长 2024-04-29 11:04
    关注

    以下内容由CHATGPT及阿里嘎多学长共同生成、有用望采纳:


    问题概括

    这个问题的目的是解决在Python中使用华为MindFormers框架进行模型加载时,遇到的配置文件中checkpoint_name_or_path属性未正确加载权重的问题。

    问题出现原因

    根据提供的错误日志和配置文件内容,问题出现的原因是尽管在配置文件中设置了checkpoint_name_or_path: clip_vit_b_32,但是框架提示说config没有这个属性或者该属性为None。这可能是因为框架在解析配置文件时没有正确地识别或使用这个属性。

    问题解决方案

    1. 确保checkpoint_name_or_path属性的值是正确的模型路径或名称。
    2. 如果checkpoint_name_or_path是预设的模型名称,则确保MindFormers框架支持该名称,并且该模型已经正确安装或包含在框架中。
    3. 如果checkpoint_name_or_path是文件路径,请确保该路径是完整的,并且文件确实存在于该位置。
    4. 检查是否有其他配置属性可能影响权重加载,比如load_checkpoint,如果这个属性被设置,它可能会覆盖checkpoint_name_or_path

    提供代码

    由于问题出现在配置文件的解析上,而不是代码实现上,因此不需要提供新的代码。但是,可以对现有配置文件进行如下修改:

    # model
    model:
      arch:
        type: CLIPModel
      model_config:
        type: CLIPConfig
        # ... 其他配置 ...
        checkpoint_name_or_path: "clip_vit_b_32"  # 确保这是一个有效的模型名称或路径
        # 如果这是一个文件路径,确保路径是正确的,例如:
        # checkpoint_name_or_path: "/path/to/clip_vit_b_32"
        # ... 其他配置 ...
    

    代码运行方式

    1. 确保你的环境已经安装了MindFormers框架和必要的依赖。
    2. 将修改后的配置文件保存,并确保它与你的运行脚本在同一个目录下,或者路径正确无误。
    3. 使用MindFormers框架的命令行工具或API来加载模型和执行训练/评估。

    代码预期运行结果

    如果配置文件修改正确,预期的结果是框架能够识别checkpoint_name_or_path属性,并成功加载模型权重,不再出现未加载权重的错误信息。

    推荐相关链接

    这些链接将帮助你获取MindFormers框架的更多信息,包括如何正确配置和使用模型权重。

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 4月29日

悬赏问题

  • ¥30 模拟电路 logisim
  • ¥15 PVE8.2.7无法成功使用a5000的vGPU,什么原因
  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价