fix VAM: funasr+pyarrow deadlock, librosa+numpy compat, reduce iter_batches batch_size
Browse filesRoot cause: funasr.AutoModel (loaded by SenseVoice encoder) and pyarrow
have a C library initialization conflict causing iter_batches to hang.
Fix:
- lazy-import pyarrow in VAMDataset/VLMDataset.__init__ (after model loads)
- remove unused pyarrow imports from dataset/common.py
- replace librosa.resample with torchaudio.resample (avoids numba+numpy 2.5
incompatibility)
- reduce iter_batches batch_size from 65536 to 4096 (lower memory)
Config updates:
- point Stage 2 (audio_proj) to omni-v Stage 1 checkpoint
- add explicit device: cuda to omni-v config
- configs/vam/vam_a2a_audio_proj_mini.yaml +1 -1
- configs/vam/vam_t2a_all_mini_omni-v.yaml +1 -0
- src/dataset/common.py +0 -2
- src/dataset/vam.py +11 -6
- src/dataset/vlm.py +1 -1
configs/vam/vam_a2a_audio_proj_mini.yaml
CHANGED
|
@@ -40,7 +40,7 @@ train:
|
|
| 40 |
save_interval: 2000
|
| 41 |
log_interval: 50
|
| 42 |
from_weight: sft_omni
|
| 43 |
-
model_dir: checkpoint/
|
| 44 |
from_resume: 0
|
| 45 |
freeze_backbone: none
|
| 46 |
mode: audio_proj # 仅训练 audio_proj
|
|
|
|
| 40 |
save_interval: 2000
|
| 41 |
log_interval: 50
|
| 42 |
from_weight: sft_omni
|
| 43 |
+
model_dir: checkpoint/vam_t2a_all_mini_omni-v # 加载 Stage 1 输出(omni-v variant)
|
| 44 |
from_resume: 0
|
| 45 |
freeze_backbone: none
|
| 46 |
mode: audio_proj # 仅训练 audio_proj
|
configs/vam/vam_t2a_all_mini_omni-v.yaml
CHANGED
|
@@ -36,6 +36,7 @@ train:
|
|
| 36 |
accumulation_steps: 1
|
| 37 |
grad_clip: 1.0
|
| 38 |
dtype: bfloat16
|
|
|
|
| 39 |
num_workers: 0
|
| 40 |
save_interval: 5000
|
| 41 |
log_interval: 50
|
|
|
|
| 36 |
accumulation_steps: 1
|
| 37 |
grad_clip: 1.0
|
| 38 |
dtype: bfloat16
|
| 39 |
+
device: cuda
|
| 40 |
num_workers: 0
|
| 41 |
save_interval: 5000
|
| 42 |
log_interval: 50
|
src/dataset/common.py
CHANGED
|
@@ -7,8 +7,6 @@ import random
|
|
| 7 |
from datasets import load_dataset, Features, Sequence, Value
|
| 8 |
from PIL import Image
|
| 9 |
from datasets import Dataset as HFDataset
|
| 10 |
-
import pyarrow as pa
|
| 11 |
-
import pyarrow.parquet as pq
|
| 12 |
|
| 13 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 14 |
|
|
|
|
| 7 |
from datasets import load_dataset, Features, Sequence, Value
|
| 8 |
from PIL import Image
|
| 9 |
from datasets import Dataset as HFDataset
|
|
|
|
|
|
|
| 10 |
|
| 11 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 12 |
|
src/dataset/vam.py
CHANGED
|
@@ -4,8 +4,6 @@ import random
|
|
| 4 |
import torch
|
| 5 |
from torch.utils.data import Dataset
|
| 6 |
from PIL import Image
|
| 7 |
-
import pyarrow as pa
|
| 8 |
-
import pyarrow.parquet as pq
|
| 9 |
|
| 10 |
from dataset.common import pre_processing_chat, post_processing_chat
|
| 11 |
|
|
@@ -20,11 +18,13 @@ class VAMDataset(Dataset):
|
|
| 20 |
scheduled_sampling=0.05,
|
| 21 |
image_token_len=64, max_samples=None):
|
| 22 |
super().__init__()
|
|
|
|
|
|
|
| 23 |
tables = []
|
| 24 |
total = 0
|
| 25 |
for p in data_path.split(','):
|
| 26 |
pf = pq.ParquetFile(p.strip())
|
| 27 |
-
for batch in pf.iter_batches(batch_size=
|
| 28 |
tables.append(batch)
|
| 29 |
total += batch.num_rows
|
| 30 |
if max_samples is not None and total >= max_samples:
|
|
@@ -119,12 +119,17 @@ class VAMDataset(Dataset):
|
|
| 119 |
import soundfile as sf
|
| 120 |
import numpy as np
|
| 121 |
import io
|
| 122 |
-
import
|
| 123 |
if not audio_bytes: return None, 0
|
| 124 |
wav, sr = sf.read(io.BytesIO(audio_bytes))
|
| 125 |
if wav.ndim > 1: wav = wav.mean(axis=1)
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
inputs = self.audio_processor(wav, sampling_rate=16000, return_tensors="pt", return_attention_mask=True)
|
| 129 |
valid_len = inputs.attention_mask.sum().item()
|
| 130 |
return self.augment_mel(inputs.input_features.squeeze(0)), valid_len
|
|
|
|
| 4 |
import torch
|
| 5 |
from torch.utils.data import Dataset
|
| 6 |
from PIL import Image
|
|
|
|
|
|
|
| 7 |
|
| 8 |
from dataset.common import pre_processing_chat, post_processing_chat
|
| 9 |
|
|
|
|
| 18 |
scheduled_sampling=0.05,
|
| 19 |
image_token_len=64, max_samples=None):
|
| 20 |
super().__init__()
|
| 21 |
+
import pyarrow as pa
|
| 22 |
+
import pyarrow.parquet as pq
|
| 23 |
tables = []
|
| 24 |
total = 0
|
| 25 |
for p in data_path.split(','):
|
| 26 |
pf = pq.ParquetFile(p.strip())
|
| 27 |
+
for batch in pf.iter_batches(batch_size=4096):
|
| 28 |
tables.append(batch)
|
| 29 |
total += batch.num_rows
|
| 30 |
if max_samples is not None and total >= max_samples:
|
|
|
|
| 119 |
import soundfile as sf
|
| 120 |
import numpy as np
|
| 121 |
import io
|
| 122 |
+
import torch
|
| 123 |
if not audio_bytes: return None, 0
|
| 124 |
wav, sr = sf.read(io.BytesIO(audio_bytes))
|
| 125 |
if wav.ndim > 1: wav = wav.mean(axis=1)
|
| 126 |
+
wav = wav.astype(np.float32)
|
| 127 |
+
if sr != 16000:
|
| 128 |
+
import torchaudio.functional as AF
|
| 129 |
+
wav_t = torch.from_numpy(wav).unsqueeze(0)
|
| 130 |
+
wav_t = AF.resample(wav_t, sr, 16000)
|
| 131 |
+
wav = wav_t.squeeze(0).numpy()
|
| 132 |
+
wav = self.augment_wav(wav)
|
| 133 |
inputs = self.audio_processor(wav, sampling_rate=16000, return_tensors="pt", return_attention_mask=True)
|
| 134 |
valid_len = inputs.attention_mask.sum().item()
|
| 135 |
return self.augment_mel(inputs.input_features.squeeze(0)), valid_len
|
src/dataset/vlm.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import io
|
| 2 |
import json
|
| 3 |
-
import pyarrow.parquet as pq
|
| 4 |
import torch
|
| 5 |
from torch.utils.data import Dataset
|
| 6 |
from PIL import Image
|
|
@@ -12,6 +11,7 @@ from dataset.common import VLM, pre_processing_chat, post_processing_chat
|
|
| 12 |
class VLMDataset(Dataset):
|
| 13 |
def __init__(self, parquet_path, tokenizer, preprocess=None, max_length=512, image_special_token='<|image_pad|>', image_token_len=64, max_samples=None):
|
| 14 |
super().__init__()
|
|
|
|
| 15 |
pf = pq.ParquetFile(parquet_path)
|
| 16 |
total = pf.metadata.num_rows
|
| 17 |
if max_samples is not None and max_samples < total:
|
|
|
|
| 1 |
import io
|
| 2 |
import json
|
|
|
|
| 3 |
import torch
|
| 4 |
from torch.utils.data import Dataset
|
| 5 |
from PIL import Image
|
|
|
|
| 11 |
class VLMDataset(Dataset):
|
| 12 |
def __init__(self, parquet_path, tokenizer, preprocess=None, max_length=512, image_special_token='<|image_pad|>', image_token_len=64, max_samples=None):
|
| 13 |
super().__init__()
|
| 14 |
+
import pyarrow.parquet as pq
|
| 15 |
pf = pq.ParquetFile(parquet_path)
|
| 16 |
total = pf.metadata.num_rows
|
| 17 |
if max_samples is not None and max_samples < total:
|