26 Commits
Author SHA1 Message Date
zhifu gao cad08344f6 fix(training): rank checkpoints only with valid validation metrics
Signed-off-by: zhifu gao <[email protected]>
2026-09-08 21:07:19 +00:00
谢翊凡 9413d7d768 fix: use torch.amp via compatibility shim (#3518)
Use the non-deprecated torch.amp APIs when available while preserving the torch.cuda.amp fallback and legacy autocast argument semantics on older PyTorch releases.
2026-08-26 20:10:53 +08:00
May d410a5652d fix(train): align DDP no_sync with gradient accumulation (#3472)
Synchronize DDP/FSDP gradients on the final microbatch of each accumulation window.

Verified with a two-rank CPU/Gloo reproduction, py_compile, diff checks, and a clean synthetic merge against current main.
2026-08-05 11:32:24 +08:00
张思远 (ZhangSiYuan)andClaude 036ed6936b fix(trainer): avoid KeyError when a checkpoint is saved at an unvalidated step (#3455)
* fix(trainer): avoid KeyError when a checkpoint is saved at an unvalidated step

When save_checkpoint_interval is not a multiple of validate_interval, a
checkpoint can be saved at a step that was never validated. The best-ckpt
comparison then indexes val_acc/val_loss_step_or_epoch[ckpt_name], raising
KeyError right after the checkpoint was already written and aborting the run.

Guard both the DeepSpeed and the torch.save checkpoint paths with .get() so
an unvalidated checkpoint is skipped for the "best" bookkeeping (and logged)
instead of crashing; fall back to 0.0 when recording saved_ckpts.

Co-Authored-By: Claude <[email protected]>

* fix(trainer): exclude unvalidated-step checkpoints from best-model ranking

Address review feedback on PR #3455. A checkpoint saved at a step that was
never validated (save_checkpoint_interval not a multiple of
validate_interval) used to be inserted into `saved_ckpts` with a fabricated
score of 0.0. Under loss-based ranking that synthetic "perfect" loss could
evict a real validated best checkpoint via keep_nbest_models pruning.

Now such checkpoints are kept on disk but excluded from `saved_ckpts`
entirely, so they never compete in best-model ranking or pruning, and
`best_step_or_epoch` only ever references validated checkpoints.

Adds regression coverage for both loss and acc ranking on the DeepSpeed
and torch.save paths, asserting an unvalidated checkpoint cannot evict a
validated best checkpoint.

* test(trainer): make unvalidated-ckpt regression catch the DeepSpeed+acc case

The fake DeepSpeed engine now writes a placeholder file per tag (mirroring
DeepSpeed's per-tag checkpoint dirs), so keep_nbest_models pruning's
smart_remove() is observable. This closes a gap where the [DeepSpeed, acc]
combination passed on the buggy code: under acc ranking the fabricated 0.0
is the minimum, so pruning deletes the unvalidated checkpoint itself rather
than the validated best, and without an on-disk artifact that deletion was
invisible.

With the fix, all 8 cases pass; on the previous code all 4 unvalidated-step
cases now fail (loss: fabricated 0.0 evicts the validated best; acc: the
unvalidated checkpoint file is pruned).

* fix(trainer): apply the same unvalidated-step guard to the non-DeepSpeed Trainer

`funasr-train` (funasr/train_utils/trainer.py) shares the identical
checkpoint-ranking code as trainer_ds.py and had the same bug: direct
indexing of `val_{acc,loss}_step_or_epoch[ckpt_name]` raised KeyError when
a checkpoint was saved at a step that was never validated, and the
keep_nbest_models bookkeeping inserted a fabricated score for such
checkpoints.

Apply the same fix: checkpoints saved at an unvalidated step are kept on
disk but excluded from saved_ckpts (no synthetic score), best_step_or_epoch
only ever references validated checkpoints, and the metric dicts are read
via .get().

Tests now parametrize over all three checkpointing paths (trainer_ds
torch.save, trainer_ds DeepSpeed, and trainer torch.save) x loss/acc.
On upstream main all 6 unvalidated-step cases fail with
`KeyError: 'model.pt.ep1.2'`; with the fix all 12 cases pass.

---------

Co-authored-by: Claude <[email protected]>
2026-08-03 14:19:25 +08:00
游雁 b710ffda91 fix: handle None scheduler_conf in trainer, add scheduler to VAD finetune
- Fix TypeError when scheduler_conf is not provided (NoneType unpacking)
- Add explicit scheduler and scheduler_conf to VAD finetune.sh
- Fixes user report in #2961
2026-06-09 14:22:12 +00:00
游雁 18a980b0dd perf: optimize training pipeline for ~3% speedup
- Use non_blocking=True for CPU→GPU data transfer (pin_memory is already enabled)
- Add persistent_workers=True and prefetch_factor=2 to DataLoader
- Reduce unnecessary all_reduce syncs to only fire at log_interval

Verified on AISHELL-1 Paraformer (H100x2, 10 epochs): val_loss matches
baseline exactly at all 10 checkpoints (10.420 final), step time reduced
from 0.2034s to 0.1972s.
2026-05-23 20:56:53 +08:00
游雁 78cc132a51 docs: add docstrings to 1950 functions across 276 files for API documentation 2026-05-21 07:52:52 +00:00
游雁 58bbfc5a9a fix: raise NotImplementedError for FSDP checkpoint saving
The FSDP branch in save_checkpoint was silently doing nothing (pass),
causing all checkpoints to be lost during FSDP training without any
warning. Now raises NotImplementedError with a clear message.
2026-05-19 17:53:53 +00:00
游雁 3e36c1d62d fix: remove eval() calls to eliminate code injection risk
- trainer.py/trainer_ds.py: replace eval(var) with float(var) for
  speed_stats logging. The values are numeric strings that only need
  type conversion, not arbitrary code execution.
- train.py/train_ds.py: replace eval(freeze_param) with
  freeze_param.split(",") for parsing comma-separated parameter names.
2026-05-19 17:51:50 +00:00
ming030890andTony Mak a750595594 Fix a few issues found during fine-tuning (#2582)
* Fix wandb log

* fix validation loss is not logged

batch_idx got reset for each epoch.
use the global step counter instead

* LR should only be updated per step, not per step+ per epoch

* add early stopping

* Fix bf16 handling

scaler is only needed for fp16

* more logs

---------

Co-authored-by: Tony Mak <[email protected]>
2025-07-04 14:25:54 +08:00
kmn1024 443bc09c11 Bugfix: Only allow rank==0 to clean up old checkpoints (#2558)
Fixes bug: https://github.com/modelscope/FunASR/issues/2557
2025-06-25 16:34:30 +08:00
游雁 e6fe602db3 step_or_epoch bugfix 2025-01-10 10:14:30 +08:00
游雁 72173314e1 decoding 2024-06-17 15:47:12 +08:00
游雁 d72df6cd2f decoding 2024-06-13 17:45:33 +08:00
游雁 c553a8db17 decoding 2024-06-13 17:38:01 +08:00
游雁 dce53b268b decoding 2024-06-13 09:56:44 +08:00
游雁 83d644c899 decoding 2024-06-12 19:47:53 +08:00
游雁 2ac79cd3f3 decoding 2024-06-12 19:27:35 +08:00
游雁 e4a69d4768 decoding 2024-06-12 19:17:55 +08:00
游雁 6a74eb706c decoding 2024-06-12 15:45:03 +08:00
游雁 407625a734 decoding 2024-06-12 15:18:42 +08:00
游雁 1c8b46a233 fix bug 2024-06-09 00:21:44 +08:00
32e7836645 update with main (#1786)
* add cmakelist

* add paraformer-torch

* add debug for funasr-onnx-offline

* fix redefinition of jieba StdExtension.hpp

* add loading torch models

* update funasr-onnx-offline

* add SwitchArg for wss-server

* add SwitchArg for funasr-onnx-offline

* update cmakelist

* update funasr-onnx-offline-rtf

* add define condition

* add gpu define for offlne-stream

* update com define

* update offline-stream

* update cmakelist

* update func CompileHotwordEmbedding

* add timestamp for paraformer-torch

* add C10_USE_GLOG for paraformer-torch

* update paraformer-torch

* fix func FunASRWfstDecoderInit

* update model.h

* fix func FunASRWfstDecoderInit

* fix tpass_stream

* update paraformer-torch

* add bladedisc for funasr-onnx-offline

* update comdefine

* update funasr-wss-server

* add log for torch

* fix GetValue BLADEDISC

* fix log

* update cmakelist

* update warmup to 10

* update funasrruntime

* add batch_size for wss-server

* add batch for bins

* add batch for offline-stream

* add batch for paraformer

* add batch for offline-stream

* fix func SetBatchSize

* add SetBatchSize for model

* add SetBatchSize for model

* fix func Forward

* fix padding

* update funasrruntime

* add dec reset for batch

* set batch default value

* add argv for CutSplit

* sort frame_queue

* sorted msgs

* fix FunOfflineInfer

* add dynamic batch for fetch

* fix FetchDynamic

* update run_server.sh

* update run_server.sh

* cpp http post server support (#1739)

* add cpp http server

* add some comment

* remove some comments

* del debug infos

* restore run_server.sh

* adapt to new model struct

* 修复了onnxruntime在macos下编译失败的错误 (#1748)

* Add files via upload

增加macos的编译支持

* Add files via upload

增加macos支持

* Add files via upload

target_link_directories(funasr PUBLIC ${ONNXRUNTIME_DIR}/lib)
target_link_directories(funasr PUBLIC ${FFMPEG_DIR}/lib)
添加 if(APPLE) 限制

---------

Co-authored-by: Yabin Li <[email protected]>

* Delete docs/images/wechat.png

* Add files via upload

* fixed the issues about seaco-onnx timestamp

* fix bug (#1764)

当语音识别结果包含 `http` 时,标点符号预测会把它会被当成 url

* fix empty asr result (#1765)

解码结果为空的语音片段,text 用空字符串

* docs

* docs

* docs

* docs

* docs

* keep empty speech result (#1772)

* docs

* docs

* update wechat QRcode

* Add python funasr api support for websocket srv (#1777)

* add python funasr_api supoort

* change little to README.md

* add core tools stream

* modified a little

* fix bug for timeout

* support for buffer decode

* add ffmpeg decode for buffer

* auto frontend

* auto frontend

* auto frontend

* auto frontend

* auto frontend

* auto frontend

* auto frontend

* auto frontend

* Dev gzf exp (#1785)

* resume from step

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* train_loss_avg train_acc_avg

* train_loss_avg train_acc_avg

* train_loss_avg train_acc_avg

* log step

* wav is not exist

* wav is not exist

* decoding

* decoding

* decoding

* wechat

* decoding key

* decoding key

* decoding key

* decoding key

* decoding key

* decoding key

* dynamic batch

* start_data_split_i=0

* total_time/accum_grad

* total_time/accum_grad

* total_time/accum_grad

* update avg slice

* update avg slice

* sensevoice sanm

* sensevoice sanm

* sensevoice sanm

---------

Co-authored-by: 北念 <[email protected]>

* auto frontend

---------

Co-authored-by: 雾聪 <[email protected]>
Co-authored-by: zhaomingwork <[email protected]>
Co-authored-by: szsteven008 <[email protected]>
Co-authored-by: Ephemeroptera <[email protected]>
Co-authored-by: 彭震东 <[email protected]>
Co-authored-by: Shi Xian <[email protected]>
Co-authored-by: 维石 <[email protected]>
Co-authored-by: 北念 <[email protected]>
2024-06-06 09:54:35 +08:00
963ba1a771 Dev gzf deepspeed (#1737)
* resume from step

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* train_loss_avg train_acc_avg

* train_loss_avg train_acc_avg

* train_loss_avg train_acc_avg

* log step

* wav is not exist

* wav is not exist

* decoding

* decoding

* decoding

* wechat

* decoding key

* decoding key

* decoding key

* decoding key

* decoding key

* decoding key

* dynamic batch

* start_data_split_i=0

* total_time/accum_grad

* total_time/accum_grad

* total_time/accum_grad

* update avg slice

* update avg slice

* sensevoice sanm

* sensevoice sanm

* add

* add

* add

* add

* deepspeed

* update with main (#1731)

* c++ runtime adapt to 1.0 (#1724)

* adapt vad runtime to 1.0

* add json

* change yml name

* add func LoadVocabFromJson

* add token file for InitAsr

* add token path for OfflineStream

* add funcOpenYaml

* add token file for InitPunc

* add token file for stream

* update punc-model

* update funasr-wss-server

* update runtime_sdk_download_tool.py

* update docker list

* Delete docs/images/wechat.png

* Add files via upload

* Emo2Vec限定选择的情感类别 (#1730)

* 限定选择的情感类别

* 使用none来禁用情感标签输出

* 修改输出接口

* 使用unuse来禁用token

---------

Co-authored-by: 常材 <[email protected]>

* bugfix

* v1.0.27

* update docs

* hf hub

* Fix incorrect assignment of 'end' attribute to 'start' in sentences list comprehension (#1680)

---------

Co-authored-by: Yabin Li <[email protected]>
Co-authored-by: gaochangfeng <[email protected]>
Co-authored-by: 常材 <[email protected]>
Co-authored-by: nsdou <[email protected]>

* docs

* docs

* deepspeed

* deepspeed

* deepspeed

* deepspeed

* update

* ds

* ds

* ds

* ds

* ds

* ds

* ds

* add

* add

* bugfix

---------

Co-authored-by: Yabin Li <[email protected]>
Co-authored-by: gaochangfeng <[email protected]>
Co-authored-by: 常材 <[email protected]>
Co-authored-by: nsdou <[email protected]>
2024-05-20 17:11:41 +08:00
961ec280af Dev gzf deepspeed (#1736)
* resume from step

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* train_loss_avg train_acc_avg

* train_loss_avg train_acc_avg

* train_loss_avg train_acc_avg

* log step

* wav is not exist

* wav is not exist

* decoding

* decoding

* decoding

* wechat

* decoding key

* decoding key

* decoding key

* decoding key

* decoding key

* decoding key

* dynamic batch

* start_data_split_i=0

* total_time/accum_grad

* total_time/accum_grad

* total_time/accum_grad

* update avg slice

* update avg slice

* sensevoice sanm

* sensevoice sanm

* add

* add

* add

* add

* deepspeed

* update with main (#1731)

* c++ runtime adapt to 1.0 (#1724)

* adapt vad runtime to 1.0

* add json

* change yml name

* add func LoadVocabFromJson

* add token file for InitAsr

* add token path for OfflineStream

* add funcOpenYaml

* add token file for InitPunc

* add token file for stream

* update punc-model

* update funasr-wss-server

* update runtime_sdk_download_tool.py

* update docker list

* Delete docs/images/wechat.png

* Add files via upload

* Emo2Vec限定选择的情感类别 (#1730)

* 限定选择的情感类别

* 使用none来禁用情感标签输出

* 修改输出接口

* 使用unuse来禁用token

---------

Co-authored-by: 常材 <[email protected]>

* bugfix

* v1.0.27

* update docs

* hf hub

* Fix incorrect assignment of 'end' attribute to 'start' in sentences list comprehension (#1680)

---------

Co-authored-by: Yabin Li <[email protected]>
Co-authored-by: gaochangfeng <[email protected]>
Co-authored-by: 常材 <[email protected]>
Co-authored-by: nsdou <[email protected]>

* docs

* docs

* deepspeed

* deepspeed

* deepspeed

* deepspeed

* update

* ds

* ds

* ds

* ds

* ds

* ds

* ds

---------

Co-authored-by: Yabin Li <[email protected]>
Co-authored-by: gaochangfeng <[email protected]>
Co-authored-by: 常材 <[email protected]>
Co-authored-by: nsdou <[email protected]>
2024-05-20 15:31:46 +08:00
a0f03bd2a8 Dev gzf deepspeed (#1732)
* resume from step

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* batch

* train_loss_avg train_acc_avg

* train_loss_avg train_acc_avg

* train_loss_avg train_acc_avg

* log step

* wav is not exist

* wav is not exist

* decoding

* decoding

* decoding

* wechat

* decoding key

* decoding key

* decoding key

* decoding key

* decoding key

* decoding key

* dynamic batch

* start_data_split_i=0

* total_time/accum_grad

* total_time/accum_grad

* total_time/accum_grad

* update avg slice

* update avg slice

* sensevoice sanm

* sensevoice sanm

* add

* add

* add

* add

* deepspeed

* update with main (#1731)

* c++ runtime adapt to 1.0 (#1724)

* adapt vad runtime to 1.0

* add json

* change yml name

* add func LoadVocabFromJson

* add token file for InitAsr

* add token path for OfflineStream

* add funcOpenYaml

* add token file for InitPunc

* add token file for stream

* update punc-model

* update funasr-wss-server

* update runtime_sdk_download_tool.py

* update docker list

* Delete docs/images/wechat.png

* Add files via upload

* Emo2Vec限定选择的情感类别 (#1730)

* 限定选择的情感类别

* 使用none来禁用情感标签输出

* 修改输出接口

* 使用unuse来禁用token

---------

Co-authored-by: 常材 <[email protected]>

* bugfix

* v1.0.27

* update docs

* hf hub

* Fix incorrect assignment of 'end' attribute to 'start' in sentences list comprehension (#1680)

---------

Co-authored-by: Yabin Li <[email protected]>
Co-authored-by: gaochangfeng <[email protected]>
Co-authored-by: 常材 <[email protected]>
Co-authored-by: nsdou <[email protected]>

* docs

---------

Co-authored-by: Yabin Li <[email protected]>
Co-authored-by: gaochangfeng <[email protected]>
Co-authored-by: 常材 <[email protected]>
Co-authored-by: nsdou <[email protected]>
2024-05-15 19:48:50 +08:00