更新vllm依赖版本至0.8.2

This commit is contained in:
xming521
2025-05-01 19:39:15 +08:00
parent 9827a24929
commit 20904b0202
7 changed files with 136 additions and 8 deletions
+1 -3
View File
@@ -14,13 +14,11 @@
## 核心功能✨
- 💫 涵盖打造数字分身的全链路方案,包括聊天数据导出、预处理、模型训练、部署
- 💬 使用微信聊天记录微调LLM,让大模型有"那味儿"
- 🎙️ 使用微信语音消息➕0.5B大模型实现高质量声音克隆 👉[WeClone-audio](https://github.com/xming521/WeClone/tree/master/weclone-audio)
- 🔗 绑定到微信、QQ、Telegram、企微、飞书机器人,实现自己的数字分身
## 特性与说明📋
> [!TIP]
> 新特性:[WeClone-audio](https://github.com/xming521/WeClone/tree/master/weclone-audio) 模块,支持对微信语音进行克隆。
> [!IMPORTANT]
> 0.2.0版本进行了全面重构,数据集目录和脚本路径全部进行了修改,拉取新代码后,`csv`文件夹放在`dataset`下,并且需要重新安装依赖。
+1 -1
View File
@@ -41,7 +41,7 @@ sparktts = [
"torchaudio>=2.6.0",
"tqdm>=4.66.5",
]
main = ["llamafactory>=0.9.2", "openai==1.76.0", "vllm==0.8.0"]
main = ["llamafactory>=0.9.2", "openai==1.76.0", "vllm==0.8.2"]
dev = ["pytest", "pyright", "ruff"]
[project.scripts]
+72
View File
@@ -0,0 +1,72 @@
import pytest
from weclone.data.clean.get_score import adjust_score_tiered
# 定义通用的参数
THRESHOLDS = [0.6, 0.3] # 置信度阈值:>=0.6 高, >=0.3 中, <0.3 低
DOWNGRADE_LEVELS = [0, 1, 2] # 对应降级幅度:高->0级, 中->1级, 低->2级
THRESHOLDS_FINE = [0.7, 0.5, 0.3]
DOWNGRADE_LEVELS_FINE = [0, 1, 2, 3] # 对应 >=0.7, >=0.5, >=0.3, <0.3
test_cases = [
# 案例 1: 高置信度
(5, [0.05, 0.05, 0.1, 0.1, 0.7], THRESHOLDS, DOWNGRADE_LEVELS, 5, "高置信度"),
# 案例 2: 中等置信度
(4, [0.1, 0.15, 0.2, 0.45, 0.1], THRESHOLDS, DOWNGRADE_LEVELS, 3, "中等置信度"),
# 案例 3: 低置信度
(4, [0.15, 0.2, 0.25, 0.25, 0.15], THRESHOLDS, DOWNGRADE_LEVELS, 2, "低置信度"),
# 案例 4: 低置信度,但原始分较低
(2, [0.3, 0.2, 0.2, 0.15, 0.15], THRESHOLDS, DOWNGRADE_LEVELS, 1, "低置信度,原始分较低"),
# 案例 5: 边界情况 - 刚好等于高阈值
(3, [0.1, 0.1, 0.6, 0.1, 0.1], THRESHOLDS, DOWNGRADE_LEVELS, 3, "边界情况 - 等于高阈值"),
# 案例 6: 边界情况 - 刚好等于中阈值
(3, [0.2, 0.2, 0.3, 0.15, 0.15], THRESHOLDS, DOWNGRADE_LEVELS, 2, "边界情况 - 等于中阈值"),
# 案例 7: 细分阈值 - 中高置信度
(4, [0.1, 0.1, 0.2, 0.55, 0.05], THRESHOLDS_FINE, DOWNGRADE_LEVELS_FINE, 3, "细分阈值 - 中高置信度"),
# 案例 8: 细分阈值 - 中低置信度
(4, [0.15, 0.15, 0.2, 0.35, 0.15], THRESHOLDS_FINE, DOWNGRADE_LEVELS_FINE, 2, "细分阈值 - 中低置信度"),
# 案例 9: 概率和异常 (预期行为是打印警告并继续计算)
(3, [0.1, 0.1, 0.5, 0.1, 0.1], THRESHOLDS, DOWNGRADE_LEVELS, 3, "概率和异常"),
]
@pytest.mark.parametrize("initial_score, probabilities, thresholds, downgrade_levels, expected_score, description", test_cases)
def test_adjust_score_tiered(initial_score, probabilities, thresholds, downgrade_levels, expected_score, description):
""" 测试 adjust_score_tiered 函数在各种情况下的表现 """
print(f"测试案例: {description}")
print(f" 输入: score={initial_score}, probs={probabilities}, thresholds={thresholds}, levels={downgrade_levels}")
adjusted_score = adjust_score_tiered(initial_score, probabilities, thresholds, downgrade_levels)
print(f" 输出: adjusted_score={adjusted_score}, 预期: {expected_score}")
assert adjusted_score == expected_score
# 测试非法输入
def test_adjust_score_invalid_input():
""" 测试非法输入是否按预期引发 ValueError """
# initial_score 无效
with pytest.raises(ValueError, match="initial_score 必须在 1 到 5 之间"):
adjust_score_tiered(0, [0.2]*5, THRESHOLDS, DOWNGRADE_LEVELS)
with pytest.raises(ValueError, match="initial_score 必须在 1 到 5 之间"):
adjust_score_tiered(6, [0.2]*5, THRESHOLDS, DOWNGRADE_LEVELS)
# probabilities 长度无效
with pytest.raises(ValueError, match="probabilities 列表必须包含 5 个元素"):
adjust_score_tiered(3, [0.2]*4, THRESHOLDS, DOWNGRADE_LEVELS)
with pytest.raises(ValueError, match="probabilities 列表必须包含 5 个元素"):
adjust_score_tiered(3, [0.1]*6, THRESHOLDS, DOWNGRADE_LEVELS) # 总和也不为1
# # probabilities 和不为 1 (现在是警告,不抛异常)
# with pytest.raises(ValueError, match="probabilities 中元素的和必须接近 1.0"):
# adjust_score_tiered(3, [0.1]*5, THRESHOLDS, DOWNGRADE_LEVELS)
# downgrade_levels 长度无效
with pytest.raises(ValueError, match="downgrade_levels 的长度必须比 thresholds 的长度多 1"):
adjust_score_tiered(3, [0.2]*5, THRESHOLDS, [0, 1])
with pytest.raises(ValueError, match="downgrade_levels 的长度必须比 thresholds 的长度多 1"):
adjust_score_tiered(3, [0.2]*5, THRESHOLDS, [0, 1, 2, 3])
# thresholds 不是降序
with pytest.raises(ValueError, match="thresholds 列表必须是降序排列的"):
adjust_score_tiered(3, [0.2]*5, [0.3, 0.6], DOWNGRADE_LEVELS)
# downgrade_levels 包含负数
with pytest.raises(ValueError, match="downgrade_levels 中的降级幅度不能为负数"):
adjust_score_tiered(3, [0.2]*5, THRESHOLDS, [0, -1, 2])
+1 -4
View File
@@ -15,7 +15,6 @@
import json
from typing import Optional
import fire
from transformers import Seq2SeqTrainingArguments
from llamafactory.data import get_dataset, get_template_and_fix_tokenizer
@@ -33,7 +32,7 @@ if is_vllm_available():
def vllm_infer(
model_name_or_path: str,
adapter_name_or_path: str = None,
adapter_name_or_path: Optional[str] = None,
dataset: str = "alpaca_en_demo",
dataset_dir: str = "data",
template: str = "default",
@@ -158,5 +157,3 @@ def vllm_infer(
print("*" * 70)
if __name__ == "__main__":
fire.Fire(vllm_infer)
View File
View File
+61
View File
@@ -0,0 +1,61 @@
import math # 引入 math 模块以使用 floor 函数(虽然当前版本未使用,但保留以备平滑调整等扩展)
def adjust_score_tiered(initial_score: int, probabilities: list[float], thresholds: list[float], downgrade_levels: list[int]) -> int:
"""
根据大模型给出评分时的概率,对原始评分进行分级置信度调整。
Args:
initial_score: 大模型给出的原始评分 (整数 1 到 5)。
probabilities: 包含 5 个评分 (1 到 5) 概率的列表。
例如 [P(1), P(2), P(3), P(4), P(5)]。
thresholds: 一个降序排列的概率阈值列表,定义置信度区间边界。
例如 [0.6, 0.3]。
downgrade_levels: 与 thresholds 对应的降级幅度列表,长度比 thresholds 多 1。
定义了每个置信度区间的降级数。例如 [0, 1, 2]。
Returns:
经过置信度调整后的最终评分 (整数 1 到 5)。
Raises:
ValueError: 如果输入参数不合法(例如概率列表长度不对,阈值未降序等)。
"""
# --- 输入校验 ---
if not (1 <= initial_score <= 5):
raise ValueError("initial_score 必须在 1 到 5 之间。")
if len(probabilities) != 5:
raise ValueError("probabilities 列表必须包含 5 个元素。")
# 检查概率和是否接近 1 (允许小的浮点误差)
if not math.isclose(sum(probabilities), 1.0, abs_tol=1e-6):
print(f"警告: 概率之和 {sum(probabilities)} 不接近 1.0。请检查概率来源。") # 打印警告而非直接报错
# raise ValueError("probabilities 中元素的和必须接近 1.0。")
if len(downgrade_levels) != len(thresholds) + 1:
raise ValueError("downgrade_levels 的长度必须比 thresholds 的长度多 1。")
if any(thresholds[i] < thresholds[i+1] for i in range(len(thresholds)-1)):
raise ValueError("thresholds 列表必须是降序排列的。")
if any(level < 0 for level in downgrade_levels):
raise ValueError("downgrade_levels 中的降级幅度不能为负数。")
# --- 算法核心 ---
# 1. 获取选中分数的概率
# 列表索引从0开始,所以评分 s 对应的索引是 s-1
try:
p_chosen = probabilities[initial_score - 1]
except IndexError:
# 这个错误理论上不应发生,因为 initial_score 已校验在 1-5 之间
raise ValueError(f"无法从 probabilities 列表获取索引 {initial_score - 1} 的值。")
# 2. 确定降级幅度
downgrade = downgrade_levels[-1] # 默认为最低置信度区间的降级幅度
# 遍历阈值列表 (从高到低)
for i in range(len(thresholds)):
if p_chosen >= thresholds[i]:
downgrade = downgrade_levels[i] # 找到对应的置信度区间
break # 停止遍历
# 3. 计算调整后的评分
preliminary_score = initial_score - downgrade
adjusted_score = max(1, preliminary_score) # 确保分数不低于 1
# 4. 返回结果
return adjusted_score