mirror of
https://github.com/ooyinet/WeClone.git
synced 2026-09-01 17:14:40 +08:00
将配置文件名从settings.json更改为settings.jsonc
This commit is contained in:
@@ -158,4 +158,5 @@ uv.lock
|
||||
output*
|
||||
|
||||
Qwen*/
|
||||
settings.jsonc
|
||||
settings.json
|
||||
|
||||
@@ -62,12 +62,12 @@ uv pip install --group main -e .
|
||||
> [!TIP]
|
||||
> 如果要使用最新的模型进行微调,需要手动安装最新版LLaMA Factory:`uv pip install --upgrade git+https://github.com/hiyouga/LLaMA-Factory.git`
|
||||
|
||||
3.将配置文件模板复制一份并重命名为`settings.json`,后续配置修改在此文件进行:
|
||||
3.将配置文件模板复制一份并重命名为`settings.jsonc`,后续配置修改在此文件进行:
|
||||
```bash
|
||||
cp settings.template.json settings.json
|
||||
cp settings.template.json settings.jsonc
|
||||
```
|
||||
> [!NOTE]
|
||||
> 训练以及推理相关配置统一在文件`settings.json`
|
||||
> 训练以及推理相关配置统一在文件`settings.jsonc`
|
||||
|
||||
4.使用以下命令测试CUDA环境是否正确配置并可被PyTorch识别,Mac不需要:
|
||||
```bash
|
||||
@@ -83,7 +83,7 @@ python -c "import torch; print('CUDA是否可用:', torch.cuda.is_available());"
|
||||
### 数据预处理
|
||||
|
||||
- 项目默认去除了数据中的手机号、身份证号、邮箱、网址。还提供了一个禁用词词库[blocked_words](dataset/blocked_words.json),可以自行添加需要过滤的词句(会默认去掉包括禁用词的整句)。
|
||||
- 执行以下命令对数据进行处理,可以根据自己的聊天风格修改settings.json的`make_dataset_args`。
|
||||
- 执行以下命令对数据进行处理,可以根据自己的聊天风格修改settings.jsonc的`make_dataset_args`。
|
||||
```bash
|
||||
python weclone/data/qa_generator.py
|
||||
```
|
||||
@@ -97,7 +97,7 @@ git clone https://www.modelscope.cn/Qwen/Qwen2.5-7B-Instruct.git
|
||||
|
||||
### 配置参数并微调模型
|
||||
|
||||
- (可选)修改[settings.json](settings.json)的`model_name_or_path`和`template`选择本地下载好的其他模型。
|
||||
- (可选)修改[settings.jsonc](settings.jsonc)的`model_name_or_path`和`template`选择本地下载好的其他模型。
|
||||
- 修改`per_device_train_batch_size`以及`gradient_accumulation_steps`来调整显存占用。
|
||||
- 可以根据自己数据集的数量和质量修改`train_sft_args`的`num_train_epochs`、`lora_rank`、`lora_dropout`等参数。
|
||||
|
||||
@@ -108,14 +108,14 @@ python weclone/train/train_sft.py
|
||||
```
|
||||
|
||||
#### 多卡训练
|
||||
取消`settings.json`中`deepspeed`行代码注释,使用以下命令多卡训练:
|
||||
取消`settings.jsonc`中`deepspeed`行代码注释,使用以下命令多卡训练:
|
||||
```bash
|
||||
uv pip install deepspeed
|
||||
deepspeed --num_gpus=使用显卡数量 weclone/train/train_sft.py
|
||||
```
|
||||
|
||||
### 使用浏览器demo简单推理
|
||||
可以在这一步测试出合适的temperature、top_p值,修改settings.json的`infer_args`后,供后续推理时使用。
|
||||
可以在这一步测试出合适的temperature、top_p值,修改settings.jsonc的`infer_args`后,供后续推理时使用。
|
||||
```bash
|
||||
python weclone/eval/web_demo.py
|
||||
```
|
||||
|
||||
@@ -52,7 +52,7 @@ step_identifiers = {
|
||||
# Order for fallback logic
|
||||
step_order = [STEP_QA, STEP_TRAIN, STEP_COPY_CKPT, STEP_API_START, STEP_EVAL, STEP_WEB_DEMO]
|
||||
|
||||
#todo 需要测试前替换成测试的settings.json 测试完再替换回来
|
||||
#todo 需要测试前替换成测试的settings.jsonc 测试完再替换回来
|
||||
|
||||
class PipelineStepError(Exception):
|
||||
"""自定义异常类,用于表示 Pipeline 步骤执行失败。"""
|
||||
|
||||
@@ -41,7 +41,7 @@ class TestWeclonePipeline(unittest.TestCase):
|
||||
# 创建简单的测试CSV数据
|
||||
cls._create_test_csv(os.path.join(chat_folder, "test_chat.csv"))
|
||||
|
||||
# 创建测试用的settings.json
|
||||
# 创建测试用的settings.jsonc
|
||||
cls._create_test_settings()
|
||||
|
||||
# 创建测试用的test_data.json用于模型评估
|
||||
@@ -77,7 +77,7 @@ class TestWeclonePipeline(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def _create_test_settings(cls):
|
||||
"""创建测试用的settings.json"""
|
||||
"""创建测试用的settings.jsonc"""
|
||||
# 简化版的设置文件,只包含测试所需的最小配置
|
||||
settings = {
|
||||
"train_sft_args": {
|
||||
@@ -121,7 +121,7 @@ class TestWeclonePipeline(unittest.TestCase):
|
||||
}
|
||||
|
||||
# 保存到临时目录
|
||||
with open(os.path.join(cls.test_dir, "settings.json"), "w", encoding="utf-8") as f:
|
||||
with open(os.path.join(cls.test_dir, "settings.jsonc"), "w", encoding="utf-8") as f:
|
||||
json.dump(settings, f, indent=4)
|
||||
|
||||
@classmethod
|
||||
|
||||
+8
-8
@@ -110,12 +110,12 @@ def _check_project_root():
|
||||
|
||||
|
||||
def _check_versions():
|
||||
"""比较本地 settings.json 版本和 pyproject.toml 中的配置文件指南版本"""
|
||||
"""比较本地 settings.jsonc 版本和 pyproject.toml 中的配置文件指南版本"""
|
||||
if tomllib is None: # Skip check if toml parser failed to import
|
||||
return
|
||||
|
||||
ROOT_DIR = Path(__file__).parent.parent
|
||||
SETTINGS_PATH = ROOT_DIR / "settings.json"
|
||||
SETTINGS_PATH = ROOT_DIR / "settings.jsonc"
|
||||
PYPROJECT_PATH = ROOT_DIR / "pyproject.toml"
|
||||
|
||||
settings_version = None
|
||||
@@ -129,11 +129,11 @@ def _check_versions():
|
||||
settings_version = settings_data.get("version")
|
||||
except Exception as e:
|
||||
logger.error(f"错误:无法读取或解析 {SETTINGS_PATH}: {e}")
|
||||
logger.error("请确保 settings.json 文件存在且格式正确。")
|
||||
logger.error("请确保 settings.jsonc 文件存在且格式正确。")
|
||||
sys.exit(1)
|
||||
else:
|
||||
logger.error(f"错误:未找到配置文件 {SETTINGS_PATH}。")
|
||||
logger.error("请确保 settings.json 文件位于项目根目录。")
|
||||
logger.error("请确保 settings.jsonc 文件位于项目根目录。")
|
||||
sys.exit(1)
|
||||
|
||||
if PYPROJECT_PATH.exists():
|
||||
@@ -150,21 +150,21 @@ def _check_versions():
|
||||
|
||||
if not settings_version:
|
||||
logger.error(f"错误:在 {SETTINGS_PATH} 中未找到 'version' 字段。")
|
||||
logger.error("请从 settings.template.json 复制或更新您的 settings.json 文件。")
|
||||
logger.error("请从 settings.template.json 复制或更新您的 settings.jsonc 文件。")
|
||||
sys.exit(1)
|
||||
|
||||
if config_guide_version:
|
||||
if settings_version != config_guide_version:
|
||||
logger.warning(
|
||||
f"警告:您的 settings.json 文件版本 ({settings_version}) 与项目建议的配置版本 ({config_guide_version}) 不一致。"
|
||||
f"警告:您的 settings.jsonc 文件版本 ({settings_version}) 与项目建议的配置版本 ({config_guide_version}) 不一致。"
|
||||
)
|
||||
logger.warning("这可能导致意外行为或错误。请从 settings.template.json 复制或更新您的 settings.json 文件。")
|
||||
logger.warning("这可能导致意外行为或错误。请从 settings.template.json 复制或更新您的 settings.jsonc 文件。")
|
||||
# TODO 根据版本号打印更新日志
|
||||
logger.warning(f"配置文件更新日志:\n{config_changelog}")
|
||||
elif PYPROJECT_PATH.exists(): # 如果文件存在但未读到版本
|
||||
logger.warning(
|
||||
f"警告:在 {PYPROJECT_PATH} 的 [tool.weclone] 下未找到 'config_version' 字段。"
|
||||
"无法确认您的 settings.json 是否为最新配置版本。"
|
||||
"无法确认您的 settings.jsonc 是否为最新配置版本。"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ from .tools import dict_to_argv
|
||||
|
||||
|
||||
def load_config(arg_type: str):
|
||||
config_path = os.environ.get("WECLONE_CONFIG_PATH", "./settings.json")
|
||||
config_path = os.environ.get("WECLONE_CONFIG_PATH", "./settings.jsonc")
|
||||
logger.info(f"Loading configuration from: {config_path}") # Add logging to see which file is loaded
|
||||
try:
|
||||
with open(config_path, "r", encoding="utf-8") as f:
|
||||
|
||||
Reference in New Issue
Block a user