61 Commits

Author SHA1 Message Date
Kakaru 2a8a013162 Unify training and ONNX-export environment, lift PyTorch 1.13 pin (#305)
* Unify training and ONNX-export environment, lift PyTorch 1.13 pin

The historical PyTorch 1.13 pin existed because two bugs surfaced in newer
torch when exporting to ONNX. Both are now fixed; training and export can
share a single environment (PyTorch >= 2.0).

Bug 1 - WaveNet diffusion ONNX export crashes on PyTorch >= 2.0
  modules/backbones/wavenet.py:83 used spec.squeeze(1), which the ONNX
  tracer lowers to an onnx::If whose two branches have different ranks
  (block0 Squeeze -> rank-3, block1 Identity -> rank-4). Shape inference
  for the downstream Conv then fails with SymbolicValueError. Replaced
  with spec[:, 0] - an unconditional rank-reducing gather, semantically
  identical (eager max-diff = 0) and producing a clean ONNX graph.

Bug 2 - non-RoPE encoder ONNX inference fails at dynamic lengths
  torch.nn.MultiheadAttention's multi_head_attention_forward gained an
  SDPA-branched implementation in torch 2.0. The branching caused the
  tracer to specialize tgt_len as a Python int constant and bake it into
  the output Reshape, so a model traced at T=40 errored with
  'requested shape:{40,2,32}' at any other length. The historical
  comment blaming espnet_positional_embedding.py was incorrect: the
  failure reproduces with a bare nn.MultiheadAttention and zero PE code,
  and survives even with the sinusoidal PE path which never touches
  the espnet module.

  Routed both non-RoPE paths through the in-house manual attention
  (MultiheadSelfAttentionWithRoPE with rotary_embed=None) that was
  already used on the RoPE path. It is fully dynamic-safe and produces
  identical eager output (max-diff 7e-7) at T=40/80/160.

Checkpoint compatibility
  Manual attention uses state_dict key 'in_proj.weight' whereas
  nn.MultiheadAttention used 'in_proj_weight'. Same shape and same
  Q/K/V-stacked-along-dim-0 semantics; utils.load_ckpt now renames the
  old key on load, so legacy ckpts continue to work with strict=True.

Diffusion graph simplification
  Each diffusion sub-graph was simplified twice: once before
  graph_extract_conditioner_projections and once after. The pre-surgery
  pass is removed. The conditioner-projection extraction rewrites the
  graph in a way that can collide with the first simplifier's node
  ordering and make the merged model fail onnx topological-sort
  validation downstream (a latent merge bug). The post-surgery
  simplifier subsumes the dropped pass, so the final graph is unchanged
  on the models that already worked, and the merge bug is avoided.
  Applies to acoustic (main diffusion), variance (pitch and multi-
  variance diffusions).

Dependency cleanup
  - Removed requirements-onnx.txt entirely (training and export share
    requirements.txt with PyTorch >= 2.0).
  - Replaced onnxsim with onnxslim (>=0.1.93) via a thin
    utils.onnx_helper.simplify_onnx wrapper. onnxslim is easier to
    install across environments and has no native build chain.
  - All torch.onnx.export calls stay on the TorchScript exporter that
    utils.onnx_helper's graph surgery was written against. The dynamo
    backend's availability differs across PyTorch versions: it first
    shipped as a separate torch.onnx.dynamo_export API in 2.1, and
    torch.onnx.export gained a 'dynamo' kwarg in 2.4 (default False,
    flipped to True in 2.9). Versions 2.0-2.3 have no such kwarg. To
    stay correct on all of them we probe
    inspect.signature(torch.onnx.export) once at import time and only
    pass dynamo=False when the kwarg exists - exposed as
    utils.onnx_helper.TORCHSCRIPT_EXPORT_KWARGS, splatted into every
    export call. Verified across torch 2.1 (no kwarg -> empty dict) and
    2.8 (kwarg present -> dynamo=False forwarded).
  - opset 15 -> 17. Verified with onnx.checker on all three model
    families.

* Unify ONNX env and bump PyTorch to >=2.4

Remove instructions to use a separate environment and requirements-onnx.txt for ONNX export; docs now recommend using the same environment for training and ONNX export and installing dependencies via the Installation section. Update requirements.txt comment to require PyTorch >= 2.4.

* Clarify PyTorch and environment recommendations

Update documentation and requirements comments to clarify environment setup: add 'uv' to the recommended virtual environment options, explicitly recommend using the latest stable PyTorch release (>= 2.4.0) in GettingStarted.md, and remove a redundant paragraph about a unified training/ONNX environment. Also adjust the top comment in requirements.txt to state that PyTorch >= 2.4 is recommended rather than required.

* Bump ONNX requirement to >=1.21.0

Update requirements.txt to change the onnx constraint from ~=1.16.0 to >=1.21.0, allowing newer ONNX releases for compatibility with updated dependencies/features.

* Unpin MonkeyType in requirements

Remove the exact version constraint for MonkeyType in requirements.txt (changed from MonkeyType==23.3.0 to MonkeyType) to allow installation of newer/compatible releases and relax strict dependency pinning.

Update requirements.txt
2026-06-21 00:18:58 +08:00
yqzhishen 44ce312264 Full implementation of multi-dictionary support (#238)
* Add multi-dictionary preprocessing and training

* Fix lang_map.json copy

* Add language embed (inject to txt_embed) for acoustic models

* Save language sequence in variance preprocessing

* Display merged phoneme groups properly in distribution plots

* Add multi-dictionary inference

* Save original phoneme texts for duration plots

* Fix duration plots displaying bug

* Explicit `languages` argument passing

* Add language embed (inject to txt_embed) for variance models

* Fix argument passing

* Add log for lang_map.json copy

* Add language embedding scale

* Add language embedding type

* Preprocessing: only apply lang embed on cross-lingual phonemes

* Inference: only apply lang embed on cross-lingual phonemes

* Revert "Add language embedding type"

This reverts commit 655e9ba9611861793297956e79ccbf329313d7f2.

* Revert lang_embed_scale

* Adapt ONNX exporters for multi-language models

* Refactor configuration schemas for datasets

* Add check of existence for merged phonemes

* Fix spk_id assignment

* Fix languages.json filename

* Fix `languages` key in dsconfig.yaml

* Set `use_lang_id` to false if there are no cross-lingual phonemes

* Support defining extra phonemes

* Refactor configs

* Prefer file copies in work_dir when loading dictionaries

* Fix cannot locate dictionary

* Fix unexpected loading error when dictionary changes

* Update toplevel.py (#219)

* Fix unexpected config passing

* Update lynxnet backbone (#228)

* Change the injection method of conditions on lynxnet (#225)

* update configurations for new-lynxnet

* update configurations for new-lynxnet

* update configurations for new-lynxnet

---------

Co-authored-by: KakaruHayate <97896816+KakaruHayate@users.noreply.github.com>

* Improve fastspeech2 encoder using Rotary Position Embedding (RoPE) in multi-head self-attention (#234)

* update multi-head self attention with RoPE

* RoPE onnx (#230)

* fix requirements.txt (#233)

* fix rope for melody encoder

* support swiglu activation for ffn

* update dependencies

---------

Co-authored-by: KakaruHayate <97896816+KakaruHayate@users.noreply.github.com>

* support mini-nsf-hifigan vocoder

* discard negative pad

* fix MHA inference using low torch version

* Fix missing phoneme list sorting

* Fix single-language dictionary parsing language tag

* Add `pitch_controllable` flag to vocoder exporter

(cherry picked from commit a6deb6b5c3)

* support noise injection

* Allow merging global phonemes and language-specific phonemes

* Check for conflicts between short names and global tags

* Finish documentation for multi-dictionary

---------

Co-authored-by: Anjo <87346264+AnAndroNerd@users.noreply.github.com>
Co-authored-by: yxlllc <33565655+yxlllc@users.noreply.github.com>
Co-authored-by: KakaruHayate <97896816+KakaruHayate@users.noreply.github.com>
Co-authored-by: yxlllc <llc1995@sina.com>
2025-03-29 22:19:59 +08:00
yqzhishen 8784ed65d3 Support LYNXNet on main branch (#218)
* [DONE]New AUX_Decoder/Backbone Network : LYNXNet (#200)

* Update __init__.py

* Update LYNXNet

* add dropout

* Lynxnet outnorm (#206)

* post-norm

* fix

* add norm+mlp

* Update LYNXNet.py

* Update LYNXNetDecoder.py

* do not need mlp

* do not need mlp

* Add out norm for LYNXNET

* Add out norm for LYNXNETDecoder

* delete lynxnet aux_decoder (#212)

* refactor configuration options

* fix onnx exporter for lynxnet

* Add Pytorch version check when export onnx (#216)

* recommended lynxnet hyperparameters for variance models

* remove invalid items

* Refactor code

* Finish configuration schemas

---------

Co-authored-by: KakaruHayate <97896816+KakaruHayate@users.noreply.github.com>
Co-authored-by: yxlllc <llc1995@sina.com>
2024-11-16 00:09:35 +08:00
autumn-2-net 76afe57e47 New generative model algorithm: Rectified Flow (#184)
Implements Rectified Flow in DiffSinger.

ref:
- https://github.com/gnobitab/RectifiedFlow
- https://github.com/yxlllc/ReFlow-VAE-SVC

---------

Co-authored-by: yqzhishen <yangqian_1015@icloud.com>
2024-04-17 22:57:54 +08:00
yqzhishen 71b8fbe5b6 Fix path type 2024-04-17 21:49:15 +08:00
yqzhishen 5ca6261deb Refactor click options 2024-04-03 21:52:08 +08:00
yqzhishen c16095bc55 Drop support for some old features and behaviors (#172)
* Drop support for discrete F0 embedding (reserved in ONNX exporter)

* Drop support for `interp_uv` configuration key

* Drop support for `train_set_name` and `valid_set_name` configuration keys

* Drop support for linear domain of random time stretching augmentation

* Drop support for `num_pad_tokens` configuration key

* Drop support for code backup before training

* Drop support for `ffn_padding` configuration key

* Drop support for random seeding

* Add placeholder to load old checkpoint

* Remove duplicate txt_embed layer (resuming may raise errors)

* Remove migration script and error message for transcriptions.txt

* Remove seed from batch shuffling

* Use direct access on some hparam keys

* Fix duplicate keys in YAML

* Rename `pndm_speedup` to `diff_speedup`
2024-02-25 20:57:02 +08:00
yqzhishen f68df7bf94 Support specifying vocoder model path for exporting 2023-11-29 02:04:26 +08:00
yqzhishen 859ad2e3ec Expose expr by default and support --freeze_glide 2023-11-25 11:24:35 +08:00
yqzhishen fbff2e8376 Enable augmentation and expose parameters by default 2023-11-20 21:22:20 +08:00
Dachun Sun 36ac5f583b Multi-node batched validation and improvement on strategy selection (#148)
* More metadata when binarize

* Picklable AttrDict

* Support other notion of 'sizes'

* Better strategy getter, Ds TB logger, and eval batch sampler.

* Add title to plots and specify figsize

* Unify batch sampler and bug fixes

* Batch and multi-device validation

* Fix imports

* Fix deadlock under multigpu and resume from ckpt

* Remove unnecessary if in base_dataset

* Move build loss to finish init and ft to build model

* Prevent repeated valid item

* Remove optimizer_idx to support lightning 2.1

* Warning message fix

* Fix val error when aux is off

* Rename fields in metadata and add doc

* Adjust respective duration logging for each speaker

* val persisent worker, module list ordering, update doc

---------

Co-authored-by: yqzhishen <yangqian_1015@icloud.com>
2023-10-29 00:37:14 +08:00
autumn-2-net 0ec98bdbf9 Shallow diffusion and aux decoder (#128)
* Add shallow diffusion API

* Support aux decoder training

* Support shallow diffusion inference

* add shallow farmwork

* add shallow farmwork

* Support lambda for aux mel loss

* Move config key

* add shallow farmework

* add shallow farmework

* add denorm

* add shallow model training switch

* Limit gradient from aux decoder

* Improve loss calculation control flow

* add   independent encoder in shallow

* Adjust lambda

* Implement shallow diffusion
There are some issues to resolve in DPM-Solver++ and UniPC

* Fix missing depth assignment

* fix bugs of shallow diffusion inference

* Fix errors and remove debug code

* Support K_step < timesteps (shallow-only diffusion)

* Fix argument passing

* Add missing checks

* add   glow decoder

* add   glow decoder

* add   convnext glow decoder

* fix fs2

* Support using gt mel as source during validation

* Clean files and configs

* Clean and refactor aux decoder

* Fix KeyError

* Support exporting shallow diffusion to ONNX

* Add missing logic to ONNX

* Rename `diff_depth` to `K_step_infer`

---------

Co-authored-by: yqzhishen <yangqian_1015@icloud.com>
Co-authored-by: autumn <2>
Co-authored-by: llc1995@sina.com <llc1995@sina.com>
2023-09-23 00:50:02 +08:00
yqzhishen 38bc407156 Implement pitch expressiveness controlling mechanism (#97)
* Add expressiveness in model `forward()`

* Support inference with static or dynamic expressiveness

* Fix assignment of `retake_`

* Format code

* Add `expressiveness` in ONNX model

* Swap input order

* Fix typo

* Adapt latest updates from main branch
2023-08-11 10:31:46 +08:00
yqzhishen 88d8ae5110 Fix wrong model loading logic when using --mel 2023-08-01 14:09:35 +08:00
yqzhishen 95e3e7d27a Perform graceful exit on KeyboardInterrupt (#119) 2023-07-20 00:19:54 +08:00
autumn-2-net 7847af2d11 support finetuning from pretrained checkpoints (#108)
* support pre_train model add doc

* Update docs for finetuning

---------

Co-authored-by: autumn <2>
Co-authored-by: yqzhishen <yangqian_1015@icloud.com>
2023-07-17 21:24:22 +08:00
yqzhishen a2e388dd71 Support variance models in drop_spk.py 2023-07-16 22:01:29 +08:00
yqzhishen b658499ec5 Support spk mix in variance exporter 2023-07-15 21:10:40 +08:00
yqzhishen 8a818b269c Update descriptions and logging 2023-07-09 20:36:29 +08:00
yqzhishen 94c0b9f240 Add PYTHONPATH envs in binarize.py and train.py 2023-06-13 20:49:30 +08:00
yqzhishen 51acdde675 Restore compatibility for Python 3.8 2023-06-13 20:45:18 +08:00
yqzhishen af4d8ec8e6 Do not support old DS files anymore 2023-06-13 19:24:21 +08:00
yqzhishen 1ab32defca Remove default value of --gender to allow None input 2023-06-13 00:43:39 +08:00
yqzhishen 4947f9b0dd Fix typo 2023-06-12 23:48:15 +08:00
yqzhishen c1208b81c3 Fix missing spk_mix in variance model inference 2023-06-02 23:29:41 +08:00
yqzhishen b5eacb135d Support speaker mix in variance model 2023-06-02 18:22:43 +08:00
yqzhishen 708ec58966 Support variance model inference from CLI 2023-06-02 00:15:26 +08:00
yqzhishen 5d0c348e62 Fix --speedup not working 2023-05-29 23:02:38 +08:00
yqzhishen 2de7a21f79 Refactor inference structure 2023-05-28 01:32:43 +08:00
yqzhishen c7303ef30c Finish variance model exporting 2023-05-21 13:52:18 +08:00
yqzhishen c29e073d02 Fix label format to CSV and add migrating scripts 2023-05-18 18:28:22 +08:00
yqzhishen 3b0748029d Support more argument formats 2023-04-11 23:09:03 +08:00
yqzhishen 8701b8955d Add script to drop speaker embedding from checkpoints 2023-04-11 22:44:09 +08:00
yqzhishen c88733b9ea Migrate some path operations to pathlib 2023-04-11 13:18:05 +08:00
yqzhishen d4943bba11 Merge pull request #75 from yqzhishen/refactor-onnx
Re-implement ONNX exporting scripts to fit new PyTorch versions
2023-04-11 01:50:33 +08:00
yqzhishen 6a6de253ef Optimize spk export and freeze logic
- if there is only one speaker, freeze him/her by default
- if there are multiple speakers but no --freeze_spk and no --export_spk is set, export them all
2023-04-09 23:44:26 +08:00
yqzhishen 81826ae1bb Adjust stdout 2023-04-09 13:16:50 +08:00
yqzhishen c9a8b105e5 Update checkpoints loading for NSF-HiFiGAN 2023-04-08 19:20:57 +08:00
yqzhishen 493a80dd96 Finish NSFHiFiGANExporter 2023-04-08 18:15:01 +08:00
yqzhishen b70626e983 Finish export.py for acoustic exporter 2023-04-08 01:13:23 +08:00
yqzhishen 664a98e038 Fix gender NoneType bug 2023-04-07 00:55:32 +08:00
yqzhishen c3b8ac6aff Merge pull request #72 from hrukalive/refactor-pl
Refactor to support PyTorch 2.0 and Lightning 2.0
2023-04-04 22:58:24 +08:00
yqzhishen 2db8751bca Re-organize infer_utils 2023-03-30 16:58:55 +08:00
yqzhishen e632dda343 Merge branch 'refactor-v2' into refactor-pl 2023-03-27 14:55:43 +08:00
yqzhishen f1bef04d3e Fix torch.load error on pure-CPU machines 2023-03-27 00:43:15 +08:00
hrukalive c1ab92af68 Revert back some small changes for diff 2023-03-26 00:11:44 -05:00
hrukalive 1a2f2c9a0a Fix for reviews 2023-03-25 23:39:04 -05:00
hrukalive 0543914f9d Auto strategy choose, gloo backend by default 2023-03-25 22:36:44 -05:00
hrukalive 2bbc42b3b0 Add env for CUDNN API change, clean more codes 2023-03-25 11:18:37 -05:00
hrukalive 93e4627a90 Use pl rankzero utils to discriminate main proc 2023-03-25 11:18:36 -05:00