Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[env] update python version and deepspeed version #2462

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ git clone https://github.com/wenet-e2e/wenet.git
- Create Conda env:

``` sh
conda create -n wenet python=3.8
conda create -n wenet python=3.10
conda activate wenet
conda install conda-forge::sox
pip install -r requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cpplint==1.6.1
torch>=2.1.2
torchaudio>=2.1.2
tqdm
deepspeed<0.13.0
deepspeed>=0.14.0
librosa
openai-whisper
pre-commit==3.5.0
Expand Down
3 changes: 1 addition & 2 deletions tools/compute_cmvn_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def __call__(self, batch):
value = item[1].strip().split(",")
assert len(value) == 3 or len(value) == 1
wav_path = value[0]
sample_rate = torchaudio.info(
wav_path).sample_rate
sample_rate = torchaudio.info(wav_path).sample_rate
resample_rate = sample_rate
# len(value) == 3 means segmented wav.scp,
# len(value) == 1 means original wav.scp
Expand Down
1 change: 0 additions & 1 deletion tools/wav2dur.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import torchaudio


scp = sys.argv[1]
dur_scp = sys.argv[2]

Expand Down
3 changes: 2 additions & 1 deletion wenet/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def Dataset(data_type,
dataset = dataset.map_ignore_error(processor.decode_wav)

singal_channel_conf = conf.get('singal_channel_conf', {})
dataset = dataset.map(partial(processor.singal_channel, **singal_channel_conf))
dataset = dataset.map(
partial(processor.singal_channel, **singal_channel_conf))

speaker_conf = conf.get('speaker_conf', None)
if speaker_conf is not None:
Expand Down
1 change: 1 addition & 0 deletions wenet/dataset/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def decode_wav(sample):
sample['sample_rate'] = sample_rate
return sample


def singal_channel(sample, channel=0):
""" Choose a channel of sample.
Inplace operation.
Expand Down
22 changes: 15 additions & 7 deletions wenet/finetune/lora/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class LoRAMultiHeadedAttention(MultiHeadedAttention):
dropout_rate (float): Dropout rate.

"""

def __init__(self,
n_head: int,
n_feat: int,
Expand All @@ -57,7 +58,10 @@ def __init__(self,
self.d_k = n_feat // n_head
self.h = n_head
self.linear_out = lora.Linear(
n_feat, n_feat, r=lora_rank, lora_alpha=lora_alpha,
n_feat,
n_feat,
r=lora_rank,
lora_alpha=lora_alpha,
lora_dropout=lora_dropout
) if lora_list and "o" in lora_list else nn.Linear(n_feat, n_feat)

Expand All @@ -69,12 +73,15 @@ def __init__(self,
bias_dict = {"q": query_bias, "k": key_bias, "v": value_bias}

for key, value in lora_qkv_dict.items():
setattr(self, f"linear_{key}",
lora.Linear(n_feat, n_feat, r=lora_rank,
lora_alpha=lora_alpha,
lora_dropout=lora_dropout,
bias=bias_dict[key])
if value else nn.Linear(n_feat, n_feat, bias_dict[key]))
setattr(
self, f"linear_{key}",
lora.Linear(n_feat,
n_feat,
r=lora_rank,
lora_alpha=lora_alpha,
lora_dropout=lora_dropout,
bias=bias_dict[key]) if value else nn.Linear(
n_feat, n_feat, bias_dict[key]))
self.dropout = nn.Dropout(p=dropout_rate)


Expand All @@ -87,6 +94,7 @@ class LoRARelPositionMultiHeadedAttention(LoRAMultiHeadedAttention,
n_feat (int): The number of features.
dropout_rate (float): Dropout rate.
"""

def __init__(self,
n_head: int,
n_feat: int,
Expand Down
36 changes: 15 additions & 21 deletions wenet/finetune/lora/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,10 @@ def __init__(
self.encoders = torch.nn.ModuleList([
TransformerEncoderLayer(
output_size,
WENET_LORA_ATTENTION_CLASSES["selfattn"](attention_heads,
output_size,
attention_dropout_rate,
query_bias, key_bias,
value_bias, use_sdpa,
n_kv_head, head_dim,
lora_rank, lora_alpha,
lora_dropout,
lora_list),
WENET_LORA_ATTENTION_CLASSES["selfattn"](
attention_heads, output_size, attention_dropout_rate,
query_bias, key_bias, value_bias, use_sdpa, n_kv_head,
head_dim, lora_rank, lora_alpha, lora_dropout, lora_list),
mlp_class(output_size, linear_units, dropout_rate, activation,
mlp_bias),
dropout_rate,
Expand Down Expand Up @@ -167,18 +162,17 @@ def __init__(
causal (bool): whether to use causal convolution or not.
key_bias: whether use bias in attention.linear_k, False for whisper models.
"""
super().__init__(input_size, output_size, attention_heads,
linear_units, num_blocks, dropout_rate,
positional_dropout_rate, attention_dropout_rate,
input_layer, pos_enc_layer_type, normalize_before,
static_chunk_size, use_dynamic_chunk, global_cmvn,
use_dynamic_left_chunk, positionwise_conv_kernel_size,
macaron_style, selfattention_layer_type,
activation_type, use_cnn_module, cnn_module_kernel,
causal, cnn_module_norm, query_bias, key_bias,
value_bias, mlp_bias, conv_bias,
gradient_checkpointing, use_sdpa, mlp_type,
layer_norm_type, norm_eps, n_kv_head, head_dim)
super().__init__(
input_size, output_size, attention_heads, linear_units, num_blocks,
dropout_rate, positional_dropout_rate, attention_dropout_rate,
input_layer, pos_enc_layer_type, normalize_before,
static_chunk_size, use_dynamic_chunk, global_cmvn,
use_dynamic_left_chunk, positionwise_conv_kernel_size,
macaron_style, selfattention_layer_type, activation_type,
use_cnn_module, cnn_module_kernel, causal, cnn_module_norm,
query_bias, key_bias, value_bias, mlp_bias, conv_bias,
gradient_checkpointing, use_sdpa, mlp_type, layer_norm_type,
norm_eps, n_kv_head, head_dim)
activation = WENET_ACTIVATION_CLASSES[activation_type]()

# self-attention module definition
Expand Down
Loading
Loading