MCPcopy Index your code
hub / github.com/YihuaJerry/ICM-LoRA

github.com/YihuaJerry/ICM-LoRA @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
50 symbols 228 edges 16 files 10 documented · 20%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

In-Context Meta LoRA Generation (IJCAI2025)

English | 简体中文

Pipeline

📌 数据准备

📂 数据集准备

请将数据集下载至 data 文件夹。Florence2 训练格式如下:

{
  "id": "image_0001",
  "image_path": "/path/to/images/image_0001.jpg",
  "height": 480,
  "width": 640,
  "suffix": "dog<loc_120><loc_85><loc_340><loc_250> person<loc_50><loc_30><loc_150><loc_200> car<loc_400><loc_150><loc_600><loc_300>"
}

🔧 训练 LoRA 参数

使用 train_lora 文件夹下的 train_lora_arg.py 脚本对大模型进行 LoRA 微调,以生成不同 rank(1-8)的 LoRA 参数。


🔄 处理 LoRA 参数

🔹 展平并归一化 LoRA 参数

  1. 运行 utils/reformat_lora_param.py 脚本,将原始 LoRA 参数标注 epoch 并移动到 param 文件夹。
  2. 运行 utils/normalizeLoraWeight_small.py 脚本,对 LoRA 参数进行展平和归一化。
  3. 观察展平后 LoRA 参数的维度,这将成为 CVAE 的 input_dim
#!/bin/bash

SOURCE_PATH=../train_lora/model_checkpoints/xxxx # 例如 dog-r=8
TARGET_PATH=../data/param_data/xxx  # 例如 dog-r=8

python3 reformat_lora_param.py --source_path "$SOURCE_PATH" --target_path "$TARGET_PATH"
python3 normalizeLoraWeight_small.py --dataset_path "$TARGET_PATH"

🏗️ 训练参数生成器

🔹 获取 Task Vector

使用 ICL/last_time_step_icl.py 脚本: - 修改数据集路径。 - 指定 LoRA 微调模型。 - 设置 output_dir,以获取最终的 hidden_state (decoder_avg_hidden_state)。 - 观察 task_vector 形状,这将成为 CVAE 的 condition_dim

🔹 训练 CVAE

使用 TrainScript_CVAE.py 训练 CVAE 模型。

python3 TrainScript_CVAE.py \
  --train_data_dir ../data/xxxx/normalized_data \
  --condition_dim xxx \
  --input_dim xxxxx \
  --task_vector_path xxxxx \
  --checkpoint_dir xxx

🔄 LoRA 重建

使用 utils/ReconstructLora_cvae.py 进行 LoRA 采样与重建。

python3 ReconstructLora_cvae.py \
  --train_data_dir ../data/xxxx/normalized_data \
  --condition_dim xxx \
  --input_dim xxxxx \
  --task_vector_path xxxxx \
  --cvae_checkpoint_path xxx \
  --datasetname "dog-r=8" \
  --normalized_lora_path xxx \
  --rank 8 # 可选:1, 2, 4, 8

✅ 测试

使用 test.py 进行测试。

python3 test.py \
  --download_location xxx \
  --datasetname xxx \
  --generated_lora xxx \
  --rank xxx

Core symbols most depended-on inside this repo

load_vectors_from_dir
called by 5
ICL/hidden_state/plot_cluster.py
load_vectors_from_dir
called by 5
ICL/hidden_state/plot.py
device
called by 4
model/CVAE_design.py
pad_sequence
called by 2
model/VAEdesign.py
decode
called by 2
model/VAEdesign.py
pad_sequence
called by 2
model/CVAE_design.py
decode
called by 2
model/CVAE_design.py
filter_annotations
called by 2
data/utils/filter_one.py

Shape

Method 26
Function 19
Class 5

Languages

Python100%

Modules by API surface

model/VAEdesign.py10 symbols
data/florence_detection_dataset.py9 symbols
model/CVAE_design.py8 symbols
TrainScript_CVAE.py8 symbols
train_lora/train_lora_arg.py4 symbols
ICL/last_time_step_icl.py3 symbols
test.py2 symbols
data/utils/filter_one.py2 symbols
utils/reformat_lora_param.py1 symbols
utils/ReconstructLora_cvae.py1 symbols
ICL/hidden_state/plot_cluster.py1 symbols
ICL/hidden_state/plot.py1 symbols

For agents

$ claude mcp add ICM-LoRA \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page