fishspeech2 / docs /ko /finetune.md
pineconeT94's picture
first commit
8b14bed
# νŒŒμΈνŠœλ‹
이 νŽ˜μ΄μ§€λ₯Ό μ—΄μ—ˆλ‹€λŠ” 것은, 사전 ν•™μŠ΅λœ 퓨샷(Few-shot) λͺ¨λΈμ˜ μ„±λŠ₯에 λ§Œμ‘±ν•˜μ§€ λͺ»ν–ˆλ‹€λŠ” 의미일 κ²ƒμž…λ‹ˆλ‹€. λ°μ΄ν„°μ…‹μ˜ μ„±λŠ₯을 ν–₯μƒμ‹œν‚€κΈ° μœ„ν•΄ λͺ¨λΈμ„ νŒŒμΈνŠœλ‹ν•˜κ³  μ‹ΆμœΌμ‹œκ² μ£ .
ν˜„μž¬ λ²„μ „μ—μ„œλŠ” 'LLAMA' λΆ€λΆ„λ§Œ νŒŒμΈνŠœλ‹ν•˜μ‹œλ©΄ λ©λ‹ˆλ‹€.
## LLAMA νŒŒμΈνŠœλ‹
### 1. 데이터셋 μ€€λΉ„
```
.
β”œβ”€β”€ SPK1
β”‚ β”œβ”€β”€ 21.15-26.44.lab
β”‚ β”œβ”€β”€ 21.15-26.44.mp3
β”‚ β”œβ”€β”€ 27.51-29.98.lab
β”‚ β”œβ”€β”€ 27.51-29.98.mp3
β”‚ β”œβ”€β”€ 30.1-32.71.lab
β”‚ └── 30.1-32.71.mp3
└── SPK2
β”œβ”€β”€ 38.79-40.85.lab
└── 38.79-40.85.mp3
```
μœ„μ™€ 같은 ν˜•μ‹μœΌλ‘œ 데이터셋을 λ³€ν™˜ν•˜μ—¬ `data` 디렉토리 μ•ˆμ— λ°°μΉ˜ν•˜μ„Έμš”. μ˜€λ””μ˜€ 파일의 ν™•μž₯μžλŠ” `.mp3`, `.wav`, `.flac` 쀑 ν•˜λ‚˜μ—¬μ•Ό ν•˜λ©°, 주석 νŒŒμΌμ€ `.lab` ν™•μž₯자λ₯Ό μ‚¬μš©ν•΄μ•Ό ν•©λ‹ˆλ‹€.
!!! info "데이터셋 ν˜•μ‹"
`.lab` 주석 νŒŒμΌμ€ μ˜€λ””μ˜€μ˜ 전사 λ‚΄μš©λ§Œ ν¬ν•¨ν•˜λ©΄ 되며, νŠΉλ³„ν•œ ν˜•μ‹μ΄ ν•„μš”ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, `hi.mp3`μ—μ„œ "Hello, goodbye"λΌλŠ” λŒ€μ‚¬λ₯Ό λ§ν•œλ‹€λ©΄, `hi.lab` νŒŒμΌμ—λŠ” "Hello, goodbye"λΌλŠ” ν•œ μ€„μ˜ ν…μŠ€νŠΈλ§Œ μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€.
!!! warning
데이터셋에 λŒ€ν•œ μŒλŸ‰ μ •κ·œν™”(loudness normalization)λ₯Ό μ μš©ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€. 이λ₯Ό μœ„ν•΄ [fish-audio-preprocess](https://github.com/fishaudio/audio-preprocess)λ₯Ό μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
```bash
fap loudness-norm data-raw data --clean
```
### 2. μ‹œλ§¨ν‹± 토큰 배치 μΆ”μΆœ
VQGAN κ°€μ€‘μΉ˜λ₯Ό λ‹€μš΄λ‘œλ“œν–ˆλŠ”μ§€ ν™•μΈν•˜μ„Έμš”. λ‹€μš΄λ‘œλ“œν•˜μ§€ μ•Šμ•˜λ‹€λ©΄ μ•„λž˜ λͺ…λ Ήμ–΄λ₯Ό μ‹€ν–‰ν•˜μ„Έμš”:
```bash
huggingface-cli download fishaudio/fish-speech-1.4 --local-dir checkpoints/fish-speech-1.4
```
이후 μ‹œλ§¨ν‹± 토큰을 μΆ”μΆœν•˜κΈ° μœ„ν•΄ μ•„λž˜ λͺ…λ Ήμ–΄λ₯Ό μ‹€ν–‰ν•˜μ„Έμš”:
```bash
python tools/vqgan/extract_vq.py data \
--num-workers 1 --batch-size 16 \
--config-name "firefly_gan_vq" \
--checkpoint-path "checkpoints/fish-speech-1.4/firefly-gan-vq-fsq-8x1024-21hz-generator.pth"
```
!!! note
μΆ”μΆœ 속도λ₯Ό 높이기 μœ„ν•΄ `--num-workers`와 `--batch-size` 값을 μ‘°μ •ν•  수 μžˆμ§€λ§Œ, GPU λ©”λͺ¨λ¦¬ ν•œλ„λ₯Ό μ΄ˆκ³Όν•˜μ§€ μ•Šλ„λ‘ μ£Όμ˜ν•˜μ„Έμš”.
VITS ν˜•μ‹μ˜ 경우, `--filelist xxx.list`λ₯Ό μ‚¬μš©ν•˜μ—¬ 파일 λͺ©λ‘μ„ 지정할 수 μžˆμŠ΅λ‹ˆλ‹€.
이 λͺ…령을 μ‹€ν–‰ν•˜λ©΄ `data` 디렉토리 μ•ˆμ— `.npy` 파일이 μƒμ„±λ©λ‹ˆλ‹€. λ‹€μŒκ³Ό 같이 ν‘œμ‹œλ©λ‹ˆλ‹€:
```
.
β”œβ”€β”€ SPK1
β”‚ β”œβ”€β”€ 21.15-26.44.lab
β”‚ β”œβ”€β”€ 21.15-26.44.mp3
β”‚ β”œβ”€β”€ 21.15-26.44.npy
β”‚ β”œβ”€β”€ 27.51-29.98.lab
β”‚ β”œβ”€β”€ 27.51-29.98.mp3
β”‚ β”œβ”€β”€ 27.51-29.98.npy
β”‚ β”œβ”€β”€ 30.1-32.71.lab
β”‚ β”œβ”€β”€ 30.1-32.71.mp3
β”‚ └── 30.1-32.71.npy
└── SPK2
β”œβ”€β”€ 38.79-40.85.lab
β”œβ”€β”€ 38.79-40.85.mp3
└── 38.79-40.85.npy
```
### 3. 데이터셋을 protobuf둜 νŒ¨ν‚Ή
```bash
python tools/llama/build_dataset.py \
--input "data" \
--output "data/protos" \
--text-extension .lab \
--num-workers 16
```
λͺ…령이 μ™„λ£Œλ˜λ©΄ `data` 디렉토리 μ•ˆμ— `quantized-dataset-ft.protos` 파일이 μƒμ„±λ©λ‹ˆλ‹€.
### 4. λ§ˆμ§€λ§‰μœΌλ‘œ, LoRAλ₯Ό μ΄μš©ν•œ νŒŒμΈνŠœλ‹
λ§ˆμ°¬κ°€μ§€λ‘œ, `LLAMA` κ°€μ€‘μΉ˜λ₯Ό λ‹€μš΄λ‘œλ“œν–ˆλŠ”μ§€ ν™•μΈν•˜μ„Έμš”. λ‹€μš΄λ‘œλ“œν•˜μ§€ μ•Šμ•˜λ‹€λ©΄ μ•„λž˜ λͺ…λ Ήμ–΄λ₯Ό μ‹€ν–‰ν•˜μ„Έμš”:
```bash
huggingface-cli download fishaudio/fish-speech-1.4 --local-dir checkpoints/fish-speech-1.4
```
λ§ˆμ§€λ§‰μœΌλ‘œ, μ•„λž˜ λͺ…λ Ήμ–΄λ₯Ό μ‹€ν–‰ν•˜μ—¬ νŒŒμΈνŠœλ‹μ„ μ‹œμž‘ν•  수 μžˆμŠ΅λ‹ˆλ‹€:
```bash
python fish_speech/train.py --config-name text2semantic_finetune \
project=$project \
[email protected]_config=r_8_alpha_16
```
!!! note
`batch_size`, `gradient_accumulation_steps` λ“±μ˜ ν•™μŠ΅ λ§€κ°œλ³€μˆ˜λ₯Ό GPU λ©”λͺ¨λ¦¬μ— 맞게 μ‘°μ •ν•˜λ €λ©΄ `fish_speech/configs/text2semantic_finetune.yaml` νŒŒμΌμ„ μˆ˜μ •ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
!!! note
Windows μ‚¬μš©μžμ˜ 경우, `nccl` 문제λ₯Ό ν”Όν•˜λ €λ©΄ `trainer.strategy.process_group_backend=gloo`λ₯Ό μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
ν›ˆλ ¨μ΄ μ™„λ£Œλ˜λ©΄ [μΆ”λ‘ ](inference.md) μ„Ήμ…˜μ„ μ°Έκ³ ν•˜μ—¬ μŒμ„±μ„ 생성할 수 μžˆμŠ΅λ‹ˆλ‹€.
!!! info
기본적으둜 λͺ¨λΈμ€ ν™”μžμ˜ λ§ν•˜λŠ” νŒ¨ν„΄λ§Œ ν•™μŠ΅ν•˜κ³  μŒμƒ‰μ€ ν•™μŠ΅ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. μŒμƒ‰μ˜ μ•ˆμ •μ„±μ„ μœ„ν•΄ ν”„λ‘¬ν”„νŠΈλ₯Ό μ‚¬μš©ν•΄μ•Ό ν•©λ‹ˆλ‹€.
μŒμƒ‰μ„ ν•™μŠ΅ν•˜λ €λ©΄ ν›ˆλ ¨ 단계λ₯Ό 늘릴 수 μžˆμ§€λ§Œ, μ΄λŠ” κ³Όμ ν•©μ˜ μœ„ν—˜μ„ μ΄ˆλž˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
ν›ˆλ ¨μ΄ λλ‚˜λ©΄ LoRA κ°€μ€‘μΉ˜λ₯Ό 일반 κ°€μ€‘μΉ˜λ‘œ λ³€ν™˜ν•œ 후에 좔둠을 μˆ˜ν–‰ν•΄μ•Ό ν•©λ‹ˆλ‹€.
```bash
python tools/llama/merge_lora.py \
--lora-config r_8_alpha_16 \
--base-weight checkpoints/fish-speech-1.4 \
--lora-weight results/$project/checkpoints/step_000000010.ckpt \
--output checkpoints/fish-speech-1.4-yth-lora/
```
!!! note
λ‹€λ₯Έ μ²΄ν¬ν¬μΈνŠΈλ„ μ‹œλ„ν•΄ λ³Ό 수 μžˆμŠ΅λ‹ˆλ‹€. μš”κ΅¬ 사항에 λ§žλŠ” κ°€μž₯ 초기 체크포인트λ₯Ό μ‚¬μš©ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€. 이듀은 μ’…μ’… 뢄포 λ°–(OOD) λ°μ΄ν„°μ—μ„œ 더 쒋은 μ„±λŠ₯을 λ°œνœ˜ν•©λ‹ˆλ‹€.