diff --git a/docs/.vuepress/notes/en/guide.ts b/docs/.vuepress/notes/en/guide.ts index 86a5eb9..d3654c3 100644 --- a/docs/.vuepress/notes/en/guide.ts +++ b/docs/.vuepress/notes/en/guide.ts @@ -24,6 +24,8 @@ export const Guide: ThemeNote = defineNoteConfig({ items: [ 'quickstart', 'tutorial', + 'selector_delta_loss', + 'selector_loss', 'selector_less', 'selector_nice', 'selector_offline_tsds', diff --git a/docs/.vuepress/notes/zh/guide.ts b/docs/.vuepress/notes/zh/guide.ts index 3bbd483..54e37ac 100644 --- a/docs/.vuepress/notes/zh/guide.ts +++ b/docs/.vuepress/notes/zh/guide.ts @@ -24,6 +24,8 @@ export const Guide: ThemeNote = defineNoteConfig({ items: [ 'quickstart', 'tutorial', + 'selector_delta_loss', + 'selector_loss', 'selector_less', 'selector_nice', 'selector_offline_tsds', diff --git a/docs/en/notes/guide/mixer/odm.md b/docs/en/notes/guide/mixer/odm.md index 8ba77ff..d8fea7d 100644 --- a/docs/en/notes/guide/mixer/odm.md +++ b/docs/en/notes/guide/mixer/odm.md @@ -1,7 +1,7 @@ --- title: ODM Data Mixer createTime: 2025/01/27 10:00:00 -icon: material-symbols:casino +icon: material-symbols:balance permalink: /en/guide/mixer/odm/ --- diff --git a/docs/en/notes/guide/selector/selector_delta_loss.md b/docs/en/notes/guide/selector/selector_delta_loss.md new file mode 100644 index 0000000..e74d3d7 --- /dev/null +++ b/docs/en/notes/guide/selector/selector_delta_loss.md @@ -0,0 +1,183 @@ +--- +title: Delta Loss Selector +createTime: 2025/12/27 00:44:11 +permalink: /en/guide/delta-loss/ +icon: carbon:select-window +--- +# Delta Loss Selector Guide + +This document explains how to use the **Delta Loss Selector** in **DataFlex**. It tracks loss reduction relative to an initial baseline and samples from a sliding window over the ranked delta-loss list. + +--- + +## 1. Method Overview + +**Delta Loss Selector** workflow: + +1. On the first selection, compute and cache **initial losses**, then return a random warmup batch. +2. On later steps, compute current losses and define $\Delta l_i = l_i^{(init)} - l_i^{(current)}$. +3. Sort samples by $\Delta l_i$ in descending order and compute a sliding-window position based on training progress. +4. Assign high sampling probability inside the window and a small base probability outside. + +**Sliding window schedule:** + +Let update index be $t$ out of $T$, and window ratio be $s$: + +$$ +u = \sigma\left(\frac{t}{T}\right), \quad +\text{start} = u \cdot (N - sN), \quad +\text{end} = \text{start} + sN +$$ + +If $\Delta l_i < 0$, the window end is truncated to avoid prioritizing samples that got worse. + + +## 2. Implementation Steps + +### Step 1: Environment Setup + +```bash +git clone https://github.com/OpenDCAI/DataFlex.git +cd DataFlex +pip install -e . +pip install llamafactory +``` + +--- + +### Step 2: Delta Loss Selector Configuration + +**Configuration file path:** +``` +DataFlex/src/dataflex/configs/components.yaml +``` + +**Example configuration:** +```yaml +delta_loss: + name: delta_loss + params: + cache_dir: ../dataflex_saves/delta_loss_output + window_size: 0.2 +``` + +**Parameter Description:** +* `cache_dir`: Cache directory; the first step stores initial losses here. +* `window_size`: Sliding window ratio for focused sampling. + +--- + +### Step 3: Dynamic Training Configuration + +**Configuration file path:** +``` +DataFlex/examples/train_lora/selectors/delta_loss.yaml +``` + +**Example configuration:** +```yaml +### model +model_name_or_path: meta-llama/Llama-3.1-8B +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_target: all +lora_rank: 16 +lora_alpha: 8 + +### dataset +dataset: alpaca_en_demo +template: llama3 +cutoff_len: 4096 +overwrite_cache: true +preprocessing_num_workers: 16 +dataloader_num_workers: 0 +seed: 42 + +### output +output_dir: ../dataflex_saves/Llama-3.1-8B/delta_loss +logging_steps: 10 +save_steps: 100 +plot_loss: true +save_only_model: false +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 1 +learning_rate: 1.0e-4 +num_train_epochs: 1.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### Dataflex args +train_type: dynamic_select +components_cfg_file: src/dataflex/configs/components.yaml +component_name: delta_loss +warmup_step: 10 +update_step: 10 +update_times: 2 + +eval_dataset: alpaca_zh_demo +``` + +--- + +### Step 4: Run Training + +```bash +FORCE_TORCHRUN=1 DISABLE_VERSION_CHECK=1 dataflex-cli train examples/train_lora/selectors/delta_loss.yaml +``` + +--- + +### Step 5: Model Merge and Export + +**Configuration file path:** + +``` +DataFlex/examples/merge_lora/llama3_lora_sft.yaml +``` + +**Example configuration:** + +```yaml +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +adapter_name_or_path: ../dataflex_saves/Llama-3.1-8B/delta_loss +template: llama3 +trust_remote_code: true + +export_dir: ../dataflex_saves/Llama-3.1-8B_lora_sft +export_size: 5 +export_device: cpu # choices: [cpu, auto] +export_legacy_format: false +``` + +**Parameter Description:** + +* `model_name_or_path`: Model name or path used for training. +* `adapter_name_or_path`: Output path of the LoRA adapter. +* `export_dir`: Directory for saving the merged result of the fine-tuned model and LoRA adapter. + +Execute the export command: + +```bash +llamafactory-cli export llama3_lora_sft.yaml +``` + +The merged model will be saved in: + +``` +/dataflex_saves/Llama-3.1-8B_lora_sft +``` + + +## 3. Model Evaluation + +It is recommended to use the [DataFlow](https://github.com/OpenDCAI/DataFlow) [Model QA Evaluation Pipeline](https://opendcai.github.io/DataFlow-Doc/zh/guide/2k5wjgls/) for systematic evaluation of the generated model. + diff --git a/docs/en/notes/guide/selector/selector_loss.md b/docs/en/notes/guide/selector/selector_loss.md new file mode 100644 index 0000000..661cc83 --- /dev/null +++ b/docs/en/notes/guide/selector/selector_loss.md @@ -0,0 +1,188 @@ +--- +title: Loss Selector +createTime: 2025/12/27 00:44:11 +permalink: /en/guide/loss/ +icon: carbon:select-window +--- +# Loss Selector Guide + +This document explains how to use the **Loss Selector** in **DataFlex**. The selector computes per-sample training loss, splits the distribution into low/medium/high bands using quantiles, and then samples with higher weight on a chosen band. + +--- + +## 1. Method Overview + +**Core idea of the Loss Selector:** + +1. During training, compute the training loss for each sample. In a multi-GPU setting, results from different processes are aligned to the full dataset using the sample index (`idx`). + + * In the current implementation, `batch_size = 1`, so the loss returned by the model corresponds to a per-sample loss. +2. On the main process, collect and deduplicate all valid sample losses, and partition samples into **low / medium / high** loss regions using quantile thresholds. +3. Assign a base weight of 1 to all valid samples, and apply an amplified weight `focus_weight` to samples in the specified focus region (`focus`). +4. Smooth the weight distribution using a temperature parameter and perform random sampling according to the resulting probability distribution; when the number of valid samples is insufficient to meet the sampling requirement, automatically switch to sampling with replacement. + +**Sampling probability:** + +Let the loss of sample ($i$) be ($l_i$), the segment weight be ($w_i$), and the temperature be ($T$): + +$$ + p_i = \frac{(w_i + \epsilon)^{1/T}}{\sum_j (w_j + \epsilon)^{1/T}} +$$ + + +## 2. Implementation Steps + +### Step 1: Environment Setup + +```bash +git clone https://github.com/OpenDCAI/DataFlex.git +cd DataFlex +pip install -e . +pip install llamafactory +``` + +--- + +### Step 2: Loss Selector Configuration + +**Configuration file path:** +``` +DataFlex/src/dataflex/configs/components.yaml +``` + +**Example configuration:** +```yaml +loss: + name: loss + params: + cache_dir: ../dataflex_saves/loss_output + focus: "medium" # low | medium | high + focus_weight: 5.0 + quantiles: [0.33, 0.66] + replacement: false + temperature: 1.0 +``` + +**Parameter Description:** +* `cache_dir`: Cache directory for selection results (`step_{id}.json` per step). +* `focus`: Target band to up-weight (`low` / `medium` / `high`, default `high`). +* `focus_weight`: Weight multiplier for the focus band. +* `quantiles`: Split points for low/medium/high, values in `[0, 1]`. +* `replacement`: Sample with replacement or not; auto-switches to replacement if needed. +* `temperature`: Distribution sharpness; `>1` smooths, `<1` sharpens. + +--- + +### Step 3: Dynamic Training Configuration + +**Configuration file path:** +``` +DataFlex/examples/train_lora/selectors/loss.yaml +``` + +**Example configuration:** +```yaml +### model +model_name_or_path: meta-llama/Llama-3.1-8B +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_target: all +lora_rank: 16 +lora_alpha: 8 + +### dataset +dataset: alpaca_en_demo +template: llama3 +cutoff_len: 4096 +overwrite_cache: true +preprocessing_num_workers: 16 +dataloader_num_workers: 0 +seed: 42 + +### output +output_dir: ../dataflex_saves/Llama-3.1-8B/loss +logging_steps: 10 +save_steps: 100 +plot_loss: true +save_only_model: false +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 1 +learning_rate: 1.0e-4 +num_train_epochs: 1.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### Dataflex args +train_type: dynamic_select +components_cfg_file: src/dataflex/configs/components.yaml +component_name: loss +warmup_step: 10 +update_step: 10 +update_times: 2 + +eval_dataset: alpaca_zh_demo +``` + +--- + +### Step 4: Run Training + +```bash +FORCE_TORCHRUN=1 DISABLE_VERSION_CHECK=1 dataflex-cli train examples/train_lora/selectors/loss.yaml +``` + + +### Step 5: Model Merge and Export + +**Configuration file path:** + +``` +DataFlex/examples/merge_lora/llama3_lora_sft.yaml +``` + +**Example configuration:** + +```yaml +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +adapter_name_or_path: ../dataflex_saves/Llama-3.1-8B/loss +template: llama3 +trust_remote_code: true + +export_dir: ../dataflex_saves/Llama-3.1-8B_lora_sft +export_size: 5 +export_device: cpu # choices: [cpu, auto] +export_legacy_format: false +``` + +**Parameter Description:** + +* `model_name_or_path`: Model name or path used for training. +* `adapter_name_or_path`: Output path of the LoRA adapter. +* `export_dir`: Directory for saving the merged result of the fine-tuned model and LoRA adapter. + +Execute the export command: + +```bash +llamafactory-cli export llama3_lora_sft.yaml +``` + +The merged model will be saved in: + +``` +/dataflex_saves/Llama-3.1-8B_lora_sft +``` + + +## 3. Model Evaluation + +It is recommended to use the [DataFlow](https://github.com/OpenDCAI/DataFlow) [Model QA Evaluation Pipeline](https://opendcai.github.io/DataFlow-Doc/zh/guide/2k5wjgls/) for systematic evaluation of the generated model. + diff --git a/docs/en/notes/guide/selector/selector_nice.md b/docs/en/notes/guide/selector/selector_nice.md index 7249f80..5c77b0f 100644 --- a/docs/en/notes/guide/selector/selector_nice.md +++ b/docs/en/notes/guide/selector/selector_nice.md @@ -2,7 +2,7 @@ title: NICE Data Selector createTime: 2025/12/17 12:00:08 permalink: /en/guide/nice/ -icon: carbon:select-02 +icon: carbon:select-window --- # NICE Selector Usage Guide diff --git a/docs/en/notes/guide/selector/selector_offline_near.md b/docs/en/notes/guide/selector/selector_offline_near.md index 8173cd8..2e967c7 100644 --- a/docs/en/notes/guide/selector/selector_offline_near.md +++ b/docs/en/notes/guide/selector/selector_offline_near.md @@ -2,7 +2,7 @@ title: Offline-Near-Selector createTime: 2025/11/27 16:02:41 permalink: /en/guide/7k0w3d92/ -icon: flowbite:fish-alt-outline +icon: carbon:select-02 --- # Offline NEAR Selector diff --git a/docs/en/notes/guide/selector/selector_offline_tsds.md b/docs/en/notes/guide/selector/selector_offline_tsds.md index 3e3af90..137ced9 100644 --- a/docs/en/notes/guide/selector/selector_offline_tsds.md +++ b/docs/en/notes/guide/selector/selector_offline_tsds.md @@ -2,7 +2,7 @@ title: Offline-Tsds-Selector createTime: 2025/11/01 21:36:21 permalink: /en/guide/im5q9cd2/ -icon: tdesign:cat +icon: carbon:select-02 --- diff --git a/docs/en/notes/guide/selector/selector_zeroth.md b/docs/en/notes/guide/selector/selector_zeroth.md index 101033c..5d588d3 100644 --- a/docs/en/notes/guide/selector/selector_zeroth.md +++ b/docs/en/notes/guide/selector/selector_zeroth.md @@ -2,7 +2,7 @@ title: Zero Order Data Selection createTime: 2025/11/03 22:58:52 permalink: /en/guide/0rfxa64a/ -icon: tabler:chart-dots-3 +icon: carbon:select-window --- # Introduction to the Zeroth Selector This document explains how to use the **Zeroth Selector** in the **DataFlex** framework to achieve dynamic selection of training data, thereby enhancing the performance of supervised fine-tuning (SFT). This method is an original selection approach that utilizes co-directional perturbations on the model for differential estimation, thereby obtaining the model's zeroth-order gradient to calculate the effective score of the data. diff --git a/docs/zh/notes/guide/mixer/odm.md b/docs/zh/notes/guide/mixer/odm.md index e06d41d..bd8ccd4 100644 --- a/docs/zh/notes/guide/mixer/odm.md +++ b/docs/zh/notes/guide/mixer/odm.md @@ -1,7 +1,7 @@ --- title: ODM 数据混合器 createTime: 2025/01/27 10:00:00 -icon: material-symbols:casino +icon: material-symbols:balance permalink: /zh/guide/mixer/odm/ --- diff --git a/docs/zh/notes/guide/selector/selector_delta_loss.md b/docs/zh/notes/guide/selector/selector_delta_loss.md new file mode 100644 index 0000000..d89333d --- /dev/null +++ b/docs/zh/notes/guide/selector/selector_delta_loss.md @@ -0,0 +1,181 @@ +--- +title: Delta Loss 数据选择器 +createTime: 2025/12/27 00:44:11 +permalink: /zh/guide/delta-loss/ +icon: carbon:select-window +--- +# Delta Loss Selector 使用介绍 + +本文档介绍如何在 **DataFlex** 框架中使用 **Delta Loss Selector**。该方法以“初始损失 - 当前损失”作为样本有效性的信号,结合滑动窗口策略进行动态采样,从而在训练过程中逐步移动关注区间。 + +--- + +## 1. 方法概述 + +**Delta Loss Selector** 的核心流程: + +1. 首次选择时计算并缓存 **初始损失**,并随机采样作为 warmup。 +2. 后续步骤计算当前损失,得到 $\Delta l_i = l_i^{(init)} - l_i^{(current)}$。 +3. 对 $\Delta l_i$ 降序排序,并按训练进度计算滑动窗口位置。 +4. 对窗口内样本赋较高采样概率,窗口外样本保留较低基准概率。 + +**滑动窗口位置:** + +设当前更新次数为 $t$,总更新次数为 $T$,窗口大小为 $s$(比例), +窗口起点通过 Sigmoid 调度获得: + +$$ +u = \sigma\left(\frac{t}{T}\right), \quad +\text{start} = u \cdot (N - sN), \quad +\text{end} = \text{start} + sN +$$ + +当 $\Delta l_i < 0$ 时,窗口右端会被截断,避免选择损失变差的样本。 + + +## 2. 实现步骤 + +### 步骤一:环境安装 + +```bash +git clone https://github.com/OpenDCAI/DataFlex.git +cd DataFlex +pip install -e . +pip install llamafactory +``` + +--- + +### 步骤二:Delta Loss Selector 参数配置 + +**配置文件路径:** +``` +DataFlex/src/dataflex/configs/components.yaml +``` + +**示例配置:** +```yaml +delta_loss: + name: delta_loss + params: + cache_dir: ../dataflex_saves/delta_loss_output + window_size: 0.2 +``` + +**参数说明:** +* `cache_dir`: 选择结果缓存路径,首次选择会保存 initial loss。 +* `window_size`: 滑动窗口大小(比例),决定每轮重点采样的区间宽度。 + +--- + +### 步骤三:动态训练配置 + +**配置文件路径:** +``` +DataFlex/examples/train_lora/selectors/delta_loss.yaml +``` + +**示例配置:** +```yaml +### model +model_name_or_path: meta-llama/Llama-3.1-8B +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_target: all +lora_rank: 16 +lora_alpha: 8 + +### dataset +dataset: alpaca_en_demo +template: llama3 +cutoff_len: 4096 +overwrite_cache: true +preprocessing_num_workers: 16 +dataloader_num_workers: 0 +seed: 42 + +### output +output_dir: ../dataflex_saves/Llama-3.1-8B/delta_loss +logging_steps: 10 +save_steps: 100 +plot_loss: true +save_only_model: false +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 1 +learning_rate: 1.0e-4 +num_train_epochs: 1.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### Dataflex args +train_type: dynamic_select +components_cfg_file: src/dataflex/configs/components.yaml +component_name: delta_loss +warmup_step: 10 +update_step: 10 +update_times: 2 + +eval_dataset: alpaca_zh_demo +``` + +--- + +### 步骤四:运行训练 + +```bash +FORCE_TORCHRUN=1 DISABLE_VERSION_CHECK=1 dataflex-cli train examples/train_lora/selectors/delta_loss.yaml +``` + +--- + +### 步骤五:模型合并与导出 + +**配置文件路径:** + +``` +DataFlex/examples/merge_lora/llama3_lora_sft.yaml +``` + +**示例配置:** + +```yaml +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +adapter_name_or_path: ../dataflex_saves/Llama-3.1-8B/delta_loss +template: llama3 +trust_remote_code: true + +export_dir: ../dataflex_saves/Llama-3.1-8B_lora_sft +export_size: 5 +export_device: cpu # choices: [cpu, auto] +export_legacy_format: false +``` +**参数说明:** +* `model_name_or_path`: 训练模型的名称或路径。 +* `adapter_name_or_path`: LoRA适配器输出路径。 +* `export_dir`: 监督微调后的模型,训练模型与LoRA适配器的合并结果。 + +执行合并导出命令: + +```bash +llamafactory-cli export llama3_lora_sft.yaml +``` + +合并后的模型将保存在如下文件夹: + +``` +/dataflex_saves/Llama-3.1-8B_lora_sft +``` + +## 3. 模型评估 + +推荐使用[DataFlow](https://github.com/OpenDCAI/DataFlow)的[模型QA能力评估流水线](https://opendcai.github.io/DataFlow-Doc/zh/guide/2k5wjgls/)对生成后的模型进行系统性评估。 + diff --git a/docs/zh/notes/guide/selector/selector_loss.md b/docs/zh/notes/guide/selector/selector_loss.md new file mode 100644 index 0000000..205a5a8 --- /dev/null +++ b/docs/zh/notes/guide/selector/selector_loss.md @@ -0,0 +1,187 @@ +--- +title: Loss 数据选择器 +createTime: 2025/12/27 00:44:11 +permalink: /zh/guide/loss/ +icon: carbon:select-window +--- +# Loss Selector 使用介绍 + +本文档介绍如何在 **DataFlex** 框架中使用 **Loss Selector**,基于样本损失分布进行动态数据选择。该方法会按分位数将样本划分为低/中/高损失区间,并对指定区间加权采样,以便在训练中更聚焦特定难度的样本。 + +--- + +## 1. 方法概述 + + +**Loss Selector** 的核心思想是: +1. 在训练过程中计算样本对应的训练损失,并在多卡环境下通过样本索引(`idx`)将各进程结果对齐到完整数据集。 + + * 当前实现使用 `batch_size=1`,因此模型返回的 loss 等价于逐样本损失。 +2. 在主进程上收集并去重所有样本的有效损失值,使用分位数阈值将样本划分为 **low / medium / high** 三个损失区间。 +3. 为所有有效样本赋予基础权重 1,并对指定关注区间(`focus`)内的样本施加放大权重 `focus_weight`。 +4. 通过温度参数对权重分布进行平滑,并依据得到的概率分布进行随机采样;当有效样本数量不足以满足采样需求时,自动切换为放回采样。 + +**采样概率:** + +设样本损失为 $l_i$,分段权重为 $w_i$,温度为 $T$: + +$$ + p_i = \frac{(w_i + \epsilon)^{1/T}}{\sum_j (w_j + \epsilon)^{1/T}} +$$ + + +## 2. 实现步骤 + +### 步骤一:环境安装 + +```bash +git clone https://github.com/OpenDCAI/DataFlex.git +cd DataFlex +pip install -e . +pip install llamafactory +``` + +--- + +### 步骤二:Loss Selector 参数配置 + +**配置文件路径:** +``` +DataFlex/src/dataflex/configs/components.yaml +``` + +**示例配置:** +```yaml +loss: + name: loss + params: + cache_dir: ../dataflex_saves/loss_output + focus: "medium" # low | medium | high + focus_weight: 5.0 + quantiles: [0.33, 0.66] + replacement: false + temperature: 1.0 +``` + +**参数说明:** +* `cache_dir`: 选择结果缓存路径(每个 step 会写入 `step_{id}.json`)。 +* `focus`: 关注区间,可选 `low` / `medium` / `high`(默认 `high`)。 +* `focus_weight`: 关注区间的权重倍数,越大越偏向该区间。 +* `quantiles`: 低/中/高损失的分位数切分点,取值在 `[0, 1]`。 +* `replacement`: 是否放回采样;若请求数大于有效样本量,会自动切换为放回采样。 +* `temperature`: 温度系数,`>1` 更平滑,`<1` 更尖锐。 + +--- + +### 步骤三:动态训练配置 + +**配置文件路径:** +``` +DataFlex/examples/train_lora/selectors/loss.yaml +``` + +**示例配置:** +```yaml +### model +model_name_or_path: meta-llama/Llama-3.1-8B +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_target: all +lora_rank: 16 +lora_alpha: 8 + +### dataset +dataset: alpaca_en_demo +template: llama3 +cutoff_len: 4096 +overwrite_cache: true +preprocessing_num_workers: 16 +dataloader_num_workers: 0 +seed: 42 + +### output +output_dir: ../dataflex_saves/Llama-3.1-8B/loss +logging_steps: 10 +save_steps: 100 +plot_loss: true +save_only_model: false +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 1 +learning_rate: 1.0e-4 +num_train_epochs: 1.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### Dataflex args +train_type: dynamic_select +components_cfg_file: src/dataflex/configs/components.yaml +component_name: loss +warmup_step: 10 +update_step: 10 +update_times: 2 + +eval_dataset: alpaca_zh_demo +``` + +--- + +### 步骤四:运行训练 + +```bash +FORCE_TORCHRUN=1 DISABLE_VERSION_CHECK=1 dataflex-cli train examples/train_lora/selectors/loss.yaml +``` + +--- + + +### 步骤五:模型合并与导出 + +**配置文件路径:** + +``` +DataFlex/examples/merge_lora/llama3_lora_sft.yaml +``` + +**示例配置:** + +```yaml +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +adapter_name_or_path: ../dataflex_saves/Llama-3.1-8B/less +template: llama3 +trust_remote_code: true + +export_dir: ../dataflex_saves/Llama-3.1-8B_lora_sft +export_size: 5 +export_device: cpu # choices: [cpu, auto] +export_legacy_format: false +``` +**参数说明:** +* `model_name_or_path`: 训练模型的名称或路径。 +* `adapter_name_or_path`: LoRA适配器输出路径。 +* `export_dir`: 监督微调后的模型,训练模型与LoRA适配器的合并结果。 + +执行合并导出命令: + +```bash +llamafactory-cli export llama3_lora_sft.yaml +``` + +合并后的模型将保存在如下文件夹: + +``` +/dataflex_saves/Llama-3.1-8B_lora_sft +``` + +## 3. 模型评估 + +推荐使用[DataFlow](https://github.com/OpenDCAI/DataFlow)的[模型QA能力评估流水线](https://opendcai.github.io/DataFlow-Doc/zh/guide/2k5wjgls/)对生成后的模型进行系统性评估。 + diff --git a/docs/zh/notes/guide/selector/selector_nice.md b/docs/zh/notes/guide/selector/selector_nice.md index d175a96..51c8ea0 100644 --- a/docs/zh/notes/guide/selector/selector_nice.md +++ b/docs/zh/notes/guide/selector/selector_nice.md @@ -2,7 +2,7 @@ title: Nice 数据选择器 createTime: 2025/12/17 12:00:08 permalink: /zh/guide/nice/ -icon: carbon:select-02 +icon: carbon:select-window --- # NICE Selector 使用介绍 diff --git a/docs/zh/notes/guide/selector/selector_offline_near.md b/docs/zh/notes/guide/selector/selector_offline_near.md index 8fb89f9..6de560e 100644 --- a/docs/zh/notes/guide/selector/selector_offline_near.md +++ b/docs/zh/notes/guide/selector/selector_offline_near.md @@ -2,7 +2,7 @@ title: Offline-Near数据选择器 createTime: 2025/11/26 23:42:41 permalink: /zh/guide/acgesu99/ -icon: flowbite:fish-alt-outline +icon: carbon:select-02 --- # Offline NEAR Selector 使用介绍 diff --git a/docs/zh/notes/guide/selector/selector_offline_tsds.md b/docs/zh/notes/guide/selector/selector_offline_tsds.md index b255994..9bdaa2e 100644 --- a/docs/zh/notes/guide/selector/selector_offline_tsds.md +++ b/docs/zh/notes/guide/selector/selector_offline_tsds.md @@ -2,7 +2,7 @@ title: Offline-Tsds 数据选择器 createTime: 2025/11/01 21:35:45 permalink: /zh/guide/vkqfowej/ -icon: tdesign:cat +icon: carbon:select-02 --- diff --git a/docs/zh/notes/guide/selector/selector_zeroth.md b/docs/zh/notes/guide/selector/selector_zeroth.md index 7aef476..ba59137 100644 --- a/docs/zh/notes/guide/selector/selector_zeroth.md +++ b/docs/zh/notes/guide/selector/selector_zeroth.md @@ -2,7 +2,7 @@ title: 零阶优化数据选择器 createTime: 2025/11/03 22:58:52 permalink: /zh/guide/wl9tf7o2/ -icon: tabler:chart-dots-3 +icon: carbon:select-window --- # 零阶选择器介绍 本文档介绍如何在 **DataFlex** 框架中使用 **Zeroth Selector** 实现训练数据的动态选择,从而提升监督微调(SFT)效果。该方法为原创选择方法,利用对模型进行同向扰动进行差分估计,进而得到模型的零阶梯度来计算数据有效分数。