fix train bugs and add train details

This commit is contained in:
chuxij
2025-05-12 18:50:54 +00:00
parent 84ba6afea3
commit ce2caec957
9 changed files with 261 additions and 143 deletions
+1 -127
View File
@@ -327,133 +327,7 @@ The `examples/input_params` directory contains sample input parameters that can
</p>
## 🔨 Train
### Prerequisites
1. Prepare the environment as described in the installation section.
2. If you plan to train a LoRA model, install the PEFT library:
```bash
pip install peft
```
3. Prepare your dataset in Huggingface format ([Huggingface Datasets documentation](https://huggingface.co/docs/datasets/index)). The dataset should contain the following fields:
- `keys`: Unique identifier for each audio sample
- `filename`: Path to the audio file
- `tags`: List of descriptive tags (e.g., `["pop", "rock"]`)
- `norm_lyrics`: Normalized lyrics text
- Optional fields:
- `speaker_emb_path`: Path to speaker embedding file (use empty string if not available)
- `recaption`: Additional tag descriptions in various formats
Example dataset entry:
```json
{
"keys": "1ce52937-cd1d-456f-967d-0f1072fcbb58",
"filename": "data/audio/1ce52937-cd1d-456f-967d-0f1072fcbb58.wav",
"tags": ["pop", "acoustic", "ballad", "romantic", "emotional"],
"speaker_emb_path": "",
"norm_lyrics": "I love you, I love you, I love you",
"recaption": {
"simplified": "pop",
"expanded": "pop, acoustic, ballad, romantic, emotional",
"descriptive": "The sound is soft and gentle, like a tender breeze on a quiet evening. It's soothing and full of longing.",
"use_cases": "Suitable for background music in romantic films or during intimate moments.",
"analysis": "pop, ballad, piano, guitar, slow tempo, romantic, emotional"
}
}
```
How to get an audio's reception?
You can use `Qwen-Omini` https://chat.qwen.ai/ to describe an audio.
Here we share the prompt we used.
```python
sys_prompt_without_tag = """Analyze the input audio and generate 6 description variants. Each variant must be <200 characters. Follow these exact definitions:
1. `simplified`: Use only one most representative tag from the valid set.
2. `expanded`: Broaden valid tags to include related sub-genres/techniques.
3. `descriptive`: Convert tags into a sensory-rich sentence based *only on the sound*. DO NOT transcribe or reference the lyrics.
4. `synonyms`: Replace tags with equivalent terms (e.g., 'strings' → 'orchestral').
5. `use_cases`: Suggest practical applications based on audio characteristics.
6. `analysis`: Analyze the audio's genre, instruments, tempo, and mood **based strictly on the audible musical elements**. Technical breakdown in specified format.
* For the `instruments` list: **Only include instruments that are actually heard playing in the audio recording.** **Explicitly ignore any instruments merely mentioned or sung about in the lyrics.** Cover all audibly present instruments.
7. `lyrical_rap_check`: if the audio is lyrical rap
**Strictly ignore any information derived solely from the lyrics when performing the analysis, especially for identifying instruments.**
**Output Format:**
```json
{
"simplified": <str>,
"expanded": <str>,
"descriptive": <str>,
"synonyms": <str>,
"use_cases": <str>,
"analysis": {
"genre": <str list>,
"instruments": <str list>,
"tempo": <str>,
"mood": <str list>
},
"lyrical_rap_check": <bool>
}
"""
```
### Training Parameters
#### Common Parameters
- `--dataset_path`: Path to your Huggingface dataset (required)
- `--checkpoint_dir`: Directory containing the base model checkpoint
- `--learning_rate`: Learning rate for training (default: 1e-4)
- `--max_steps`: Maximum number of training steps (default: 2000000)
- `--precision`: Training precision, e.g., "bf16-mixed" (default) or "fp32"
- `--devices`: Number of GPUs to use (default: 1)
- `--num_nodes`: Number of compute nodes to use (default: 1)
- `--accumulate_grad_batches`: Gradient accumulation steps (default: 1)
- `--num_workers`: Number of data loading workers (default: 8)
- `--every_n_train_steps`: Checkpoint saving frequency (default: 2000)
- `--every_plot_step`: Frequency of generating evaluation samples (default: 2000)
- `--exp_name`: Experiment name for logging (default: "text2music_train_test")
- `--logger_dir`: Directory for saving logs (default: "./exps/logs/")
#### Base Model Training
Train the base model with:
```bash
python trainer.py --dataset_path "path/to/your/dataset" --checkpoint_dir "path/to/base/checkpoint" --exp_name "your_experiment_name"
```
#### LoRA Training
For LoRA training, you need to provide a LoRA configuration file:
```bash
python trainer.py --dataset_path "path/to/your/dataset" --checkpoint_dir "path/to/base/checkpoint" --lora_config_path "path/to/lora_config.json" --exp_name "your_lora_experiment"
```
Example LoRA configuration file (lora_config.json):
```json
{
"r": 16,
"lora_alpha": 32,
"target_modules": [
"speaker_embedder",
"linear_q",
"linear_k",
"linear_v",
"to_q",
"to_k",
"to_v",
"to_out.0"
]
}
```
### Advanced Training Options
- `--shift`: Flow matching shift parameter (default: 3.0)
- `--gradient_clip_val`: Gradient clipping value (default: 0.5)
- `--gradient_clip_algorithm`: Gradient clipping algorithm (default: "norm")
- `--reload_dataloaders_every_n_epochs`: Frequency to reload dataloaders (default: 1)
- `--val_check_interval`: Validation check interval (default: None)
See [TRAIN_INSTRUCTION.md](./TRAIN_INSTRUCTION.md) for detailed training instructions.
## 📜 License & Disclaimer