Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于segformer进行模型压缩 #3789

Open
1 task done
wwma opened this issue Aug 29, 2024 · 3 comments
Open
1 task done

关于segformer进行模型压缩 #3789

wwma opened this issue Aug 29, 2024 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@wwma
Copy link

wwma commented Aug 29, 2024

问题确认 Search before asking

  • 我已经搜索过问题,但是没有找到解答。I have searched the question and found no related answer.

请提出你的问题 Please ask your question

Global:
  model_dir: slim/output_model
  model_filename: model.pdmodel
  params_filename: model.pdiparams

Distillation:
  alpha: 1.0
  loss: l2
  node:
  - block4.2.mlp.fc2 # change to the name of the output of the last conv in the model.pdmodel in netron

QuantAware:
  onnx_format: False
  quantize_op_types:
  - conv2d
  - depthwise_conv2d

TrainConfig:
  epochs: 1
  eval_iter: 1000
  learning_rate: 0.0005
  optimizer_builder:
    optimizer: 
      type: SGD
    weight_decay: 4.0e-05  

使用的配置文件如上,当不注释Distillation部分是,会提示错误:

I0829 09:00:02.586479 20276 program_interpreter.cc:212] New Executor is Running.
W0829 09:00:02.897599 20276 gpu_resources.cc:119] Please NOTE: device: 0, GPU Compute Capability: 8.6, Driver API Version: 12.2, Runtime API Version: 
11.2
W0829 09:00:02.904767 20276 gpu_resources.cc:164] device: 0, cuDNN Version: 8.2.
2024-08-29 09:00:04,526-INFO: devices: gpu
2024-08-29 09:00:25,280-INFO: Selected strategies: ['qat_dis']
2024-08-29 09:00:27,045-INFO: train config.distill_node_pair: ['block4.2.mlp.fc2']
Traceback (most recent call last):
  File "deploy\slim\act\run_seg.py", line 205, in <module>
    main(args)
  File "deploy\slim\act\run_seg.py", line 199, in main
    ac.compress()
  File "C:\Users\DELL\.conda\envs\paddle\lib\site-packages\paddleslim\auto_compression\compressor.py", line 586, in compress
    self.single_strategy_compress(strategy, config, strategy_idx,
  File "C:\Users\DELL\.conda\envs\paddle\lib\site-packages\paddleslim\auto_compression\compressor.py", line 769, in single_strategy_compress
    train_program_info, test_program_info = self._prepare_program(
  File "C:\Users\DELL\.conda\envs\paddle\lib\site-packages\paddleslim\auto_compression\compressor.py", line 506, in _prepare_program
    train_program_info, test_program_info = build_distill_program(
  File "C:\Users\DELL\.conda\envs\paddle\lib\site-packages\paddleslim\auto_compression\create_compressed_program.py", line 380, in build_distill_program
    distill_loss, loss_dict = _parse_distill_loss(
  File "C:\Users\DELL\.conda\envs\paddle\lib\site-packages\paddleslim\auto_compression\create_compressed_program.py", line 163, in _parse_distill_loss    assert len(node) % 2 == 0, \
AssertionError: distill_node_pair config wrong, the length needs to be an even number

参考https://github.com/PaddlePaddle/PaddleSlim/issues/1631,对Distillation部分进行注释,提示错误

2024-08-29 09:04:13,725-INFO: Selected strategies: []
Traceback (most recent call last):
  File "deploy\slim\act\run_seg.py", line 205, in <module>
    main(args)
  File "deploy\slim\act\run_seg.py", line 199, in main
    ac.compress()
  File "C:\Users\DELL\.conda\envs\paddle\lib\site-packages\paddleslim\auto_compression\compressor.py", line 577, in compress
    assert len(self._strategy) > 0
AssertionError

这是说明模型没有自动寻找最后一个带参数节点作为蒸馏节点吗?
同时使用了netron可视化模型,某些层输出Tensor名称如下:
image
并没有输出名称

@wwma wwma added the question Further information is requested label Aug 29, 2024
@zhang-prog
Copy link
Collaborator

  - block4.2.mlp.fc2 # change to the name of the output of the last conv in the model.pdmodel in netron

这里有说明 model.pdmodel in netron
看起来你在netron 中导入的是 model.pdparams ,所以看不到正确的模型结构。应该参考这里导出预测模型,将 model.pdmodel 放入netron 中。

@wwma
Copy link
Author

wwma commented Aug 30, 2024

非常感谢,现在已经可以正常运行了

@zhang-prog
Copy link
Collaborator

好的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants