tests
This commit is contained in:
@@ -58,6 +58,13 @@ from qwen_tts.core.models.modeling_qwen3_tts import Qwen3TTSForConditionalG
|
|||||||
from qwen_tts.core.models.configuration_qwen3_tts import Qwen3TTSConfig
|
from qwen_tts.core.models.configuration_qwen3_tts import Qwen3TTSConfig
|
||||||
from qwen_tts.core.models.processing_qwen3_tts import Qwen3TTSProcessor
|
from qwen_tts.core.models.processing_qwen3_tts import Qwen3TTSProcessor
|
||||||
from transformers import AutoConfig, AutoModel, AutoProcessor
|
from transformers import AutoConfig, AutoModel, AutoProcessor
|
||||||
|
from transformers.utils import logging as hf_logging
|
||||||
|
|
||||||
|
# Silence the GenerationConfig validator that warns "flags are not valid
|
||||||
|
# and may be ignored" for temperature / top_k / top_p when do_sample=False.
|
||||||
|
# Those flags ride along inside the checkpoint generation_config and the
|
||||||
|
# greedy path drops them on purpose, the warning is just noise here.
|
||||||
|
hf_logging.set_verbosity_error()
|
||||||
|
|
||||||
# Register the Qwen3-TTS classes once per process. Calling twice raises a
|
# Register the Qwen3-TTS classes once per process. Calling twice raises a
|
||||||
# ValueError inside transformers, hence the guard.
|
# ValueError inside transformers, hence the guard.
|
||||||
@@ -378,3 +385,14 @@ def compare_exact_i32(name, dump_cpp, dump_pt, label):
|
|||||||
pct = 100.0 * float(np.mean(ai[:n] == bi[:n]))
|
pct = 100.0 * float(np.mean(ai[:n] == bi[:n]))
|
||||||
print(f"[Cossim] {label} exact: {pct:.2f}% ({n} values)")
|
print(f"[Cossim] {label} exact: {pct:.2f}% ({n} values)")
|
||||||
return pct
|
return pct
|
||||||
|
|
||||||
|
# Greedy generation kwargs shared by every cossim script. do_sample=False
|
||||||
|
# alone selects argmax, top_k / top_p / temperature are intentionally
|
||||||
|
# omitted because GenerationConfig flags them as "not valid" warnings when
|
||||||
|
# do_sample=False. The subtalker_* keys are custom kwargs forwarded to the
|
||||||
|
# talker forward, the talker validator is bypassed by the script main.
|
||||||
|
GEN_KWARGS_GREEDY = dict(
|
||||||
|
do_sample = False,
|
||||||
|
subtalker_dosample = False,
|
||||||
|
repetition_penalty = 1.0,
|
||||||
|
)
|
||||||
|
|||||||
@@ -87,31 +87,12 @@ def main():
|
|||||||
# the strict validator. Disable it on the talker only.
|
# the strict validator. Disable it on the talker only.
|
||||||
model.talker._validate_model_kwargs = lambda *a, **k: None
|
model.talker._validate_model_kwargs = lambda *a, **k: None
|
||||||
|
|
||||||
# Greedy hardcoded : argmax on both talker c0 and code predictor sub
|
|
||||||
# codes. Stochastic mode is not exercised here because the F32 drift
|
|
||||||
# between torch CUDA cuBLAS and ggml CUDA matmul on Qwen3 norm_w
|
|
||||||
# inflated activations propagates through the FFN and flips multinomial
|
|
||||||
# picks in flat distributions, breaking bit exactness. Argmax is robust
|
|
||||||
# to that drift, so greedy gives 100 percent CodesFull match and
|
|
||||||
# validates the full forward + sampling chain.
|
|
||||||
gen_kwargs = dict(
|
|
||||||
do_sample = False,
|
|
||||||
top_k = 1,
|
|
||||||
top_p = 1.0,
|
|
||||||
temperature = 1.0,
|
|
||||||
subtalker_dosample = False,
|
|
||||||
subtalker_top_k = 1,
|
|
||||||
subtalker_top_p = 1.0,
|
|
||||||
subtalker_temperature = 1.0,
|
|
||||||
repetition_penalty = 1.0,
|
|
||||||
)
|
|
||||||
|
|
||||||
talker_codes_list, _ = model.generate(
|
talker_codes_list, _ = model.generate(
|
||||||
input_ids=[input_ids],
|
input_ids=[input_ids],
|
||||||
languages=[args.lang],
|
languages=[args.lang],
|
||||||
non_streaming_mode=True,
|
non_streaming_mode=True,
|
||||||
max_new_tokens=args.max_new_tokens,
|
max_new_tokens=args.max_new_tokens,
|
||||||
**gen_kwargs,
|
**cc.GEN_KWARGS_GREEDY,
|
||||||
)
|
)
|
||||||
codes = talker_codes_list[0]
|
codes = talker_codes_list[0]
|
||||||
print(f"[Python] Codes shape: {tuple(codes.shape)} (T_frames, num_code_groups)")
|
print(f"[Python] Codes shape: {tuple(codes.shape)} (T_frames, num_code_groups)")
|
||||||
|
|||||||
@@ -147,18 +147,6 @@ def main():
|
|||||||
# the strict validator. Disable it on the talker only.
|
# the strict validator. Disable it on the talker only.
|
||||||
model.talker._validate_model_kwargs = lambda *a, **k: None
|
model.talker._validate_model_kwargs = lambda *a, **k: None
|
||||||
|
|
||||||
gen_kwargs = dict(
|
|
||||||
do_sample = False,
|
|
||||||
top_k = 1,
|
|
||||||
top_p = 1.0,
|
|
||||||
temperature = 1.0,
|
|
||||||
subtalker_dosample = False,
|
|
||||||
subtalker_top_k = 1,
|
|
||||||
subtalker_top_p = 1.0,
|
|
||||||
subtalker_temperature = 1.0,
|
|
||||||
repetition_penalty = 1.0,
|
|
||||||
)
|
|
||||||
|
|
||||||
# voice_clone_prompt dict mirrors what _prompt_items_to_voice_clone_prompt
|
# voice_clone_prompt dict mirrors what _prompt_items_to_voice_clone_prompt
|
||||||
# builds for a single ICL prompt item : ref_code is the [T_codec, K]
|
# builds for a single ICL prompt item : ref_code is the [T_codec, K]
|
||||||
# tensor, ref_spk_embedding is the [hidden] tensor, x_vector_only=False
|
# tensor, ref_spk_embedding is the [hidden] tensor, x_vector_only=False
|
||||||
@@ -177,7 +165,7 @@ def main():
|
|||||||
languages=[args.lang],
|
languages=[args.lang],
|
||||||
non_streaming_mode=False,
|
non_streaming_mode=False,
|
||||||
max_new_tokens=args.max_new_tokens,
|
max_new_tokens=args.max_new_tokens,
|
||||||
**gen_kwargs,
|
**cc.GEN_KWARGS_GREEDY,
|
||||||
)
|
)
|
||||||
codes = talker_codes_list[0]
|
codes = talker_codes_list[0]
|
||||||
print(f"[Python] Codes shape: {tuple(codes.shape)} (T_frames, num_code_groups)")
|
print(f"[Python] Codes shape: {tuple(codes.shape)} (T_frames, num_code_groups)")
|
||||||
|
|||||||
@@ -113,18 +113,6 @@ def main():
|
|||||||
# the strict validator. Disable it on the talker only.
|
# the strict validator. Disable it on the talker only.
|
||||||
model.talker._validate_model_kwargs = lambda *a, **k: None
|
model.talker._validate_model_kwargs = lambda *a, **k: None
|
||||||
|
|
||||||
gen_kwargs = dict(
|
|
||||||
do_sample = False,
|
|
||||||
top_k = 1,
|
|
||||||
top_p = 1.0,
|
|
||||||
temperature = 1.0,
|
|
||||||
subtalker_dosample = False,
|
|
||||||
subtalker_top_k = 1,
|
|
||||||
subtalker_top_p = 1.0,
|
|
||||||
subtalker_temperature = 1.0,
|
|
||||||
repetition_penalty = 1.0,
|
|
||||||
)
|
|
||||||
|
|
||||||
talker_codes_list, _ = model.generate(
|
talker_codes_list, _ = model.generate(
|
||||||
input_ids=[input_ids],
|
input_ids=[input_ids],
|
||||||
instruct_ids=instruct_ids_arg,
|
instruct_ids=instruct_ids_arg,
|
||||||
@@ -132,7 +120,7 @@ def main():
|
|||||||
speakers=[args.speaker],
|
speakers=[args.speaker],
|
||||||
non_streaming_mode=True,
|
non_streaming_mode=True,
|
||||||
max_new_tokens=args.max_new_tokens,
|
max_new_tokens=args.max_new_tokens,
|
||||||
**gen_kwargs,
|
**cc.GEN_KWARGS_GREEDY,
|
||||||
)
|
)
|
||||||
codes = talker_codes_list[0]
|
codes = talker_codes_list[0]
|
||||||
print(f"[Python] Codes shape: {tuple(codes.shape)} (T_frames, num_code_groups)")
|
print(f"[Python] Codes shape: {tuple(codes.shape)} (T_frames, num_code_groups)")
|
||||||
|
|||||||
@@ -103,25 +103,13 @@ def main():
|
|||||||
# the strict validator. Disable it on the talker only.
|
# the strict validator. Disable it on the talker only.
|
||||||
model.talker._validate_model_kwargs = lambda *a, **k: None
|
model.talker._validate_model_kwargs = lambda *a, **k: None
|
||||||
|
|
||||||
gen_kwargs = dict(
|
|
||||||
do_sample = False,
|
|
||||||
top_k = 1,
|
|
||||||
top_p = 1.0,
|
|
||||||
temperature = 1.0,
|
|
||||||
subtalker_dosample = False,
|
|
||||||
subtalker_top_k = 1,
|
|
||||||
subtalker_top_p = 1.0,
|
|
||||||
subtalker_temperature = 1.0,
|
|
||||||
repetition_penalty = 1.0,
|
|
||||||
)
|
|
||||||
|
|
||||||
talker_codes_list, _ = model.generate(
|
talker_codes_list, _ = model.generate(
|
||||||
input_ids=[input_ids],
|
input_ids=[input_ids],
|
||||||
instruct_ids=[instruct_ids],
|
instruct_ids=[instruct_ids],
|
||||||
languages=[args.lang],
|
languages=[args.lang],
|
||||||
non_streaming_mode=True,
|
non_streaming_mode=True,
|
||||||
max_new_tokens=args.max_new_tokens,
|
max_new_tokens=args.max_new_tokens,
|
||||||
**gen_kwargs,
|
**cc.GEN_KWARGS_GREEDY,
|
||||||
)
|
)
|
||||||
codes = talker_codes_list[0]
|
codes = talker_codes_list[0]
|
||||||
print(f"[Python] Codes shape: {tuple(codes.shape)} (T_frames, num_code_groups)")
|
print(f"[Python] Codes shape: {tuple(codes.shape)} (T_frames, num_code_groups)")
|
||||||
|
|||||||
Reference in New Issue
Block a user