修改内容

  1. 由于openprompt 未适配最新 transformers,requirements.txt 增加 transformers≤4.27.1;
  2. https://github.com/huggingface/transformers/commit/f270b960d6b755d5355a0f193ba71f47131c86b8
  3. examples/examples_prompt/data_processors/tasks.pyexamples/tutorial/0_regex.py 修复小错误;
  4. inspect_module_statistics() 方法增加从NPU设备读取显存;
  5. 增加针对 NPU 设备运行文件 examples/tutorial/1_with_openprompt_npu.pyexamples/examples_prompt/src/run_npu.py

适配项目

opendelta.utils.cuda

定义三个函数get_device()get_dtype()move_dict_to_cuda()

虽然函数名带 cuda,但是可以指定传入 device,用于 move dict to npu 也没有问题,暂时不动。

DeltaCenter 下线

DeltaCenter 已下线,需要适配。

ModelBase

inspect_module_statistics() 方法从NPU读取 memory_allocatedmax_memory_allocated

图片

openprompt

transformers

需锁定版本 <=4.27.1

InputFeature

InputFeature 继承自 dict,实现了 to() 方法,to() 方法封装了 cuda() 方法。

可以也封装一个 npu() 方法,但是不封装使用 to() 方法也可以。

BMTrain

BMTrain 适配 NPU 后进行适配。

t5-base测试

生成config

cd examples/examples_prompt
python configs/gen_t5.py --job adapter_t5-base

该操作会在 examples_prompt/configs下生成 adapter_t5-base 文件夹,内含各种配置。

运行

可使用新增的 run_npu.py 运行,结合文档,运行方式详见下面的 vscode launch.json

{
            "name": "run t5 npu",
            "type": "debugpy",
            "request": "launch",
            "program": "src/run_npu.py",
            "console": "integratedTerminal",
            "cwd": "${workspaceFolder}/examples/examples_prompt",
            "args": [
                "configs/adapter_t5-base/superglue-cb.json",
                "--model_name_or_path",
                "google-t5/t5-base",
                "--tokenizer_name",
                "google-t5/t5-base",
                "--finetuned_delta_path",
                "/home/guozr/ckpt",
                "--num_train_epochs",
                "20",
                "--bottleneck_dim",
                "24",
                "--delay_push",
                "True",
            ],
        },