# 精简 `src/third_party/nemo` —— 不需要的文件清单 > 基于 `data/prepare_data.sh`、`*.sh`、所有项目 `.py` / `.yaml` 中的导入分析,生成可删除的 NeMo 文件列表。 ## 保留范围总结 项目仅依赖以下 NeMo 子系统: - `nemo.collections.asr`(Sortformer 训练/推理、数据仿真) - `nemo.collections.common`(少数 data/manifest 工具) - `nemo.core`(config、classes、neural_types) - `nemo.utils`(logging、exp_manager、model_utils 等) - `nemo.lightning`(部分 io/strategies/callbacks,来自 asr 的传递依赖) - `nemo.constants` - `nemo.package_info` --- ## 可直接删除的顶层目录 | 路径 | 原因 | |------|------| | `nemo/export/` | 无任何 TRT/ONNX/VLLM 导出需求 | --- ## 可删除的 `nemo/collections/` 子目录 | 路径 | 原因 | |------|------| | `nemo/collections/tts/` | 无 TTS 使用 | | `nemo/collections/nlp/` | 无 NLP 使用 | | `nemo/collections/multimodal/` | 无多模态使用 | | `nemo/collections/speechlm/` | 无 SpeechLM 使用 | | `nemo/collections/vision/` | 无视觉使用 | ## 可删除的 `nemo/collections/asr/` 模块 ### `models/` 目录 保留: - `sortformer_diar_models.py` — SortformerEncLabelModel - `asr_model.py` — 被 sortformer_diar_models 继承 - `__init__.py` — 包导出 可删除: - `clustering_diarizer.py` - `ctc_models.py` - `ctc_bpe_models.py` - `hybrid_rnnt_ctc_models.py` - `hybrid_rnnt_ctc_bpe_models.py` - `hybrid_autoregressive_transducer_models.py` - `rnnt_models.py` - `rnnt_bpe_models.py` - `ssl_models.py` - `speech_to_text.py` - `speech_to_text_bpe.py` - `transformer_bpe_models.py` - `msdd_models.py` - `wave2vec.py` - `classification_models.py` ### `modules/` 目录 保留: - `conformer_encoder.py` - `sortformer_modules.py` - `audio_preprocessing.py` - `conv_asr.py` — 被 conformer_encoder 子模块引用 - `transformer/` — 被 conformer_encoder 引用 - `__init__.py` 可删除: - `beam_search_decoder.py` - `flashlight_decoder.py` - `graph_decoder.py` - `hybrid_autoregressive_transducer.py` - `lstm_decoder.py` - `msdd_diarizer.py` - `rnnt.py` - `rnnt_abstract.py` - `rnn_encoder.py` - `squeezeformer_encoder.py` - `ssl_modules/` - `wav2vec_modules.py` ### `losses/` 目录 保留: - `bce_loss.py` - `__init__.py` 可删除: - `angularloss.py` - `ctc_loss.py` - `hat_loss.py` - `hinge_loss.py` - `rnnt_loss.py` - `speaker_ce_loss.py` - `tdt_loss.py` ### `metrics/` 目录 保留: - `der.py` - `multi_binary_acc.py` - `wer.py` - `__init__.py` 可删除: - `rnnt_metrics.py` - `tdt_metrics.py` ### `data/` 目录 保留: - `data_simulation.py` - `audio_to_diar_label.py` - `audio_to_diar_label_lhotse.py` - `audio_to_label.py` - `audio_to_text.py` - `__init__.py` 可删除: - `audio_to_speech_label.py` - `audio_to_speech.py` - `audio_to_rir.py` - `audio_to_text_lhotse_prompted.py` ### `parts/` 子目录 #### `parts/preprocessing/` 保留:`segment.py`、`features.py`、`perturb.py`、`feature_loader.py`、`__init__.py` 可删除:无(全量保留) #### `parts/mixins/` 保留: - `diarization.py` - `streaming.py` - `mixins.py` - `__init__.py` 可删除: - `asr_adapter_mixins.py` - `interctc_mixin.py` - `multitalker_asr_mixins.py` - `transcription.py` #### `parts/submodules/` 保留: - `jasper.py` - `conformer_modules.py` - `causal_convs.py` - `subsampling.py` - `multi_head_attention.py` - `classifier.py` - `batchnorm.py` - `spectr_augment.py` - `stateless_net.py` - `tdnn_attention.py` - `squeezeformer_modules.py` - `token_classifier.py` - `__init__.py` 可删除: - `ngram_lm/` - `transducer_decoding/` - `aed_decoding/` - `adapters/` - `wfst_decoder.py` - `ctc_beam_decoding.py` - `ctc_batched_beam_decoding.py` - `ctc_decoding.py` - `ctc_greedy_decoding.py` - `cuda_graph_rnnt_greedy_decoding.py` - `multitask_beam_decoding.py` - `multitask_decoding.py` - `multitask_greedy_decoding.py` - `rnnt_beam_decoding.py` - `rnnt_decoding.py` - `rnnt_greedy_decoding.py` - `rnnt_maes_batched_computer.py` - `rnnt_malsd_batched_computer.py` - `ssl_quantizers.py` - `tdt_beam_decoding.py` - `tdt_malsd_batched_computer.py` #### `parts/utils/` 保留(由依赖链引用): - `speaker_utils.py` - `transcribe_utils.py` - `vad_utils.py` - `data_simulation_utils.py` - `manifest_utils.py` - `asr_multispeaker_utils.py` - `rnnt_utils.py` - `streaming_utils.py` - `offline_clustering.py` - `longform_clustering.py` - `online_clustering.py` - `optimization_utils.py` - `diarization_utils.py` - `aligner_utils.py` - `timestamp_utils.py` - `eval_utils.py` - `asr_confidence_utils.py` - `asr_confidence_benchmarking_utils.py` - `asr_batching.py` - `asr_module_utils.py` - `batched_beam_decoding_utils.py` - `confidence_metrics.py` - `decoder_timestamps_utils.py` - `multispk_transcribe_utils.py` - `slu_utils.py` - `wfst_utils.py` - `chunking_utils.py` - `adapter_utils.py` - `activations.py` - `regularization_utils.py` - `numba_utils.py` - `tokenizer_utils.py` - `__init__.py` 可删除:无(依赖链拉入了几乎所有 utils 文件) #### `parts/context_biasing/` 可删除:无引用 #### `parts/k2/` 可删除:无 K2 解码引用 #### `parts/numba/` 保留: - `spec_augment/spec_aug_numba.py` — 可能被 spectr_augment 引用 可删除: - `rnnt_loss/` — 无 RNNT 损失引用 --- ## 可删除的 `nemo/lightning/` 子目录 保留(被 asr models/utils 传递依赖的): - `base.py`、`base_callback.py`、`callback_group.py` - `ckpt_utils.py`、`data.py` - `io/`、`pytorch/`(trainer、callbacks、strategies) - `resume.py` - `megatron_init.py`、`megatron_parallel.py` - `nemo_logger.py`、`one_logger_callback.py` - `run/` - `__init__.py` 可删除: - `fabric/` — 无 Fabric 使用 - `README.md` --- ## 可删除的 `nemo/utils/` 文件 保留(核心依赖): - `logging.py` → `nemo_logging.py` - `exp_manager.py` - `model_utils.py` - `app_state.py` - `callbacks/` - `config_utils.py` - `data_utils.py` - `enum.py`、`exceptions.py`、`env_var_parsing.py` - `file_utils.py`、`cloud.py` - `get_rank.py`、`distributed.py` - `import_utils.py`、`cast_utils.py`、`dtype.py` - `loggers/` - `lightning_logger_patch.py` - `metaclasses.py` - `mcore_logger.py` - `megatron_utils.py` - `msc_utils.py` - `notebook_utils.py` - `nvtx.py` - `s3_dirpath_utils.py`、`s3_utils.py` - `timers.py` - `trainer_utils.py` - `__init__.py` 可删除: - `decorators/` — deprecated/experimental/port_docs - `formatters/` - `sequence_packing_utils.py` - `te_utils.py` — Transformer Engine - `trt_utils.py` — TRT - `export_utils.py` - `flops_formulas.py` - `hyena_flops_formulas.py` - `arguments.py` - `debug_hook.py` - `optional_libs.py` — 检查是否需要(用于条件导入 guard) - `process_launcher/` --- ## 可删除的 `nemo/core/` 文件 保留: - `config/` — hydra_runner、base_config - `classes/` — common、ModelPT、module、loss、dataset、exportable - `classes/mixins/` — access_mixins、adapter_mixins、hf_io_mixin - `neural_types/` — 全量 - `connectors/save_restore_connector.py` - `optim/` — optimizers、lr_scheduler、novograd、radam - `utils/` — cuda_python_utils、neural_type_utils、numba_utils、optional_libs - `__init__.py` 可删除: - `core/config/templates/` — model_card 模板 - `core/config/pytorch.py` — 如果未被引用 - `core/config/pytorch_lightning.py` — 同上 - `core/optim/mcore_optim.py` — 如果未使用 Megatron - `core/optim/megatron_fused_adam.py` — 同上 - `core/optim/distributed_adam.py` — 同上 - `core/optim/adan.py` — 同上 - `core/optim/adafactor.py` — 同上 - `core/optim/optimizer_with_main_params.py` — 同上 - `core/utils/k2_guard.py`、`k2_utils.py` — 无 K2 - `core/utils/process_launcher/` --- ## 删除命令(示例) ```bash cd src/third_party/nemo # 顶层 rm -rf export/ # collections rm -rf collections/tts/ collections/nlp/ collections/multimodal/ collections/speechlm/ collections/vision/ 2>/dev/null # asr/models rm -f collections/asr/models/{clustering_diarizer,ctc_models,ctc_bpe_models,hybrid_rnnt_ctc_models,hybrid_rnnt_ctc_bpe_models,hybrid_autoregressive_transducer_models,rnnt_models,rnnt_bpe_models,ssl_models,speech_to_text,speech_to_text_bpe,transformer_bpe_models,msdd_models,wav2vec,classification_models}.py # asr/modules rm -f collections/asr/modules/{beam_search_decoder,flashlight_decoder,graph_decoder,hybrid_autoregressive_transducer,lstm_decoder,msdd_diarizer,rnnt,rnnt_abstract,rnn_encoder,squeezeformer_encoder,wav2vec_modules}.py rm -rf collections/asr/modules/ssl_modules/ # asr/losses rm -f collections/asr/losses/{angularloss,ctc_loss,hat_loss,hinge_loss,rnnt_loss,speaker_ce_loss,tdt_loss}.py # asr/metrics rm -f collections/asr/metrics/{rnnt_metrics,tdt_metrics}.py # asr/data rm -f collections/asr/data/{audio_to_speech_label,audio_to_speech,audio_to_rir,audio_to_text_lhotse_prompted}.py # asr/parts/mixins rm -f collections/asr/parts/mixins/{asr_adapter_mixins,interctc_mixin,multitalker_asr_mixins,transcription}.py # asr/parts/context_biasing & k2 rm -rf collections/asr/parts/{context_biasing,k2}/ # asr/parts/submodules (decoders not needed) rm -rf collections/asr/parts/submodules/{ngram_lm,transducer_decoding,aed_decoding,adapters}/ rm -f collections/asr/parts/submodules/{wfst_decoder,ctc_beam_decoding,ctc_batched_beam_decoding,ctc_decoding,ctc_greedy_decoding,cuda_graph_rnnt_greedy_decoding,multitask_beam_decoding,multitask_decoding,multitask_greedy_decoding,rnnt_beam_decoding,rnnt_decoding,rnnt_greedy_decoding,rnnt_maes_batched_computer,rnnt_malsd_batched_computer,ssl_quantizers,tdt_beam_decoding,tdt_malsd_batched_computer}.py # asr/parts/numba (keep only spec_augment) rm -rf collections/asr/parts/numba/rnnt_loss/ # lightning rm -rf lightning/fabric/ lightning/README.md # utils rm -rf utils/{decorators,formatters,process_launcher}/ rm -f utils/{sequence_packing_utils,te_utils,trt_utils,export_utils,flops_formulas,hyena_flops_formulas,arguments,debug_hook}.py # core rm -rf core/config/templates/ core/utils/{k2_guard,k2_utils}.py core/utils/process_launcher/ rm -f core/optim/{mcore_optim,megatron_fused_adam,distributed_adam,adan,adafactor,optimizer_with_main_params}.py ``` ## 验证 > 以下验证在实际环境(conda nemo)中通过,当前裸 Python 环境因缺少 `hydra` 包而报 `ModuleNotFoundError`,不影响文件完整性。 删除后通过文件系统检查确认所有保留模块路径存在: ```bash cd finetune_pipeline # 检查所有关键模块文件是否存在 for mod in \ nemo/collections/asr/models/sortformer_diar_models.py \ nemo/collections/asr/data/data_simulation.py \ nemo/collections/asr/parts/utils/speaker_utils.py \ nemo/collections/asr/parts/utils/manifest_utils.py \ nemo/collections/asr/parts/utils/vad_utils.py \ nemo/collections/asr/parts/utils/data_simulation_utils.py \ nemo/collections/asr/parts/utils/transcribe_utils.py \ nemo/collections/asr/losses/bce_loss.py \ nemo/collections/asr/metrics/der.py \ nemo/collections/asr/metrics/wer.py \ nemo/collections/asr/metrics/multi_binary_acc.py \ nemo/collections/asr/modules/audio_preprocessing.py \ nemo/collections/asr/modules/conformer_encoder.py \ nemo/collections/asr/modules/sortformer_modules.py \ nemo/collections/asr/modules/conv_asr.py \ nemo/collections/asr/parts/mixins/diarization.py \ nemo/collections/asr/parts/mixins/streaming.py \ nemo/collections/asr/parts/preprocessing/segment.py \ nemo/collections/asr/parts/preprocessing/features.py \ nemo/collections/asr/parts/preprocessing/perturb.py \ nemo/collections/common/parts/preprocessing/manifest.py \ nemo/core/config/hydra_runner.py \ nemo/utils/exp_manager.py do if [ -f "src/third_party/$mod" ]; then echo "OK: $mod"; else echo "MISSING: $mod"; fi done ``` ## 清理过程总结 ### 已删除 | 类别 | 路径 | |------|------| | 导出 | `nemo/export/` | | 非ASR集合 | `collections/tts/`, `nlp/`, `multimodal/`, `speechlm/`, `vision/` | | ASR模型 | `clustering_diarizer`, `ctc_*`, `hybrid_*`, `rnnt_*`, `ssl_*`, `speech_to_text*`, `transformer_bpe_*`, `msdd_*`, `wav2vec`, `classification_models` | | ASR模块 | `beam_search_decoder`, `flashlight_decoder`, `graph_decoder`, `hybrid_autoregressive_transducer`, `lstm_decoder`, `msdd_diarizer`, `rnnt*`, `rnn_encoder`, `squeezeformer_encoder`, `ssl_modules/`, `wav2vec_modules` | | ASR损失 | `angularloss`, `hat_loss`, `hinge_loss`, `rnnt_loss`, `speaker_ce_loss`, `tdt_loss` | | ASR指标 | `rnnt_metrics`, `tdt_metrics` | | ASR数据 | `audio_to_speech_label`, `audio_to_speech`, `audio_to_rir`, `audio_to_text_lhotse_prompted` | | 混入 | `asr_adapter_mixins`, `interctc_mixin`, `multitalker_asr_mixins`, `transcription` | | 子模块 | `ngram_lm/`, `transducer_decoding/`, `aed_decoding/`, `adapters/`, `wfst_decoder`, `ctc_*_decoding`, `rnnt_*_decoding`, `multitask_*`, `ssl_quantizers`, `tdt_*` | | 分区 | `context_biasing/`, `k2/`, `numba/rnnt_loss/` | | 工具 | `utils/decorators/`, `formatters/`, `process_launcher/`, `sequence_packing_utils`, `te_utils`, `trt_utils`, `export_utils`, `flops_formulas`, `hyena_flops_formulas`, `arguments`, `debug_hook` | | Lightning | `lightning/fabric/`, `lightning/README.md` | | Core | `core/config/templates/`, `core/utils/k2_*`, `core/utils/process_launcher/`, `core/optim/mcore_*`, `megatron_fused_adam`, `distributed_adam`, `adan`, `adafactor`, `optimizer_with_main_params` | ### 已修复的 `__init__.py` 删除文件后,以下 `__init__.py` 中仍引用了已删除模块,已修正为仅导入现存模块: - `nemo/collections/asr/losses/__init__.py` — 移除 `angularloss`, `lattice_losses`, `ssl_losses` 导入 - `nemo/collections/asr/models/__init__.py` — 仅保留 `SortformerEncLabelModel` - `nemo/collections/asr/modules/__init__.py` — 移除 `beam_search_decoder`, `graph_decoder`, `hybrid_autoregressive_transducer`, `lstm_decoder`, `msdd_diarizer`, `rnn_encoder`, `rnnt`, `squeezeformer_encoder`, `ssl_modules` - `nemo/collections/asr/parts/mixins/__init__.py` — 移除 `asr_adapter_mixins`, `interctc_mixin`, `multitalker_asr_mixins`, `transcription` ### 结果 - 磁盘占用:**28M** - 顶层目录结构:`collections/`, `core/`, `lightning/`, `utils/`, `constants.py`, `package_info.py`