mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
Merge branch 'dev_gzf' of github.com:alibaba-damo-academy/FunASR into dev_gzf
merge
This commit is contained in:
commit
ee3e3ff570
@ -1,16 +1,15 @@
|
|||||||
"""Receptance Weighted Key Value (RWKV) block definition.
|
#!/usr/bin/env python3
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
Based/modified from https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v4/src/model.py
|
# Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved.
|
||||||
|
# MIT License (https://opensource.org/licenses/MIT)
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Dict, Optional, Tuple
|
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
|
from typing import Dict, Optional, Tuple
|
||||||
|
|
||||||
from funasr.models.rwkv_bat.rwkv_attention import EncoderSelfAttention, DecoderSelfAttention
|
|
||||||
from funasr.models.rwkv_bat.rwkv_feed_forward import FeedForward
|
|
||||||
from funasr.models.transformer.layer_norm import LayerNorm
|
from funasr.models.transformer.layer_norm import LayerNorm
|
||||||
|
from funasr.models.rwkv_bat.rwkv_feed_forward import FeedForward
|
||||||
|
from funasr.models.rwkv_bat.rwkv_attention import EncoderSelfAttention, DecoderSelfAttention
|
||||||
|
|
||||||
|
|
||||||
class RWKV(torch.nn.Module):
|
class RWKV(torch.nn.Module):
|
||||||
"""RWKV module.
|
"""RWKV module.
|
||||||
|
|||||||
@ -1,17 +1,14 @@
|
|||||||
"""Attention (time mixing) modules for RWKV block.
|
#!/usr/bin/env python3
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
Based/Modified from https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v4/src/model.py.
|
# Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved.
|
||||||
|
# MIT License (https://opensource.org/licenses/MIT)
|
||||||
Some variables are renamed according to https://github.com/huggingface/transformers/blob/main/src/transformers/models/rwkv/modeling_rwkv.py.
|
|
||||||
|
|
||||||
""" # noqa
|
|
||||||
|
|
||||||
import math
|
import math
|
||||||
from importlib.util import find_spec
|
import torch
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from importlib.util import find_spec
|
||||||
from typing import List, Optional, Tuple, Union
|
from typing import List, Optional, Tuple, Union
|
||||||
|
|
||||||
import torch
|
|
||||||
|
|
||||||
wkv_kernel_encoder = None
|
wkv_kernel_encoder = None
|
||||||
wkv_kernel_decoder = None
|
wkv_kernel_decoder = None
|
||||||
|
|||||||
@ -1,17 +1,20 @@
|
|||||||
"""RWKV encoder definition for Transducer models."""
|
#!/usr/bin/env python3
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
import math
|
# Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved.
|
||||||
from typing import Dict, List, Optional, Tuple
|
# MIT License (https://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
|
from typing import Dict, List, Optional, Tuple
|
||||||
|
|
||||||
from funasr.models.encoder.abs_encoder import AbsEncoder
|
from funasr.register import tables
|
||||||
from funasr.models.rwkv_bat.rwkv import RWKV
|
from funasr.models.rwkv_bat.rwkv import RWKV
|
||||||
from funasr.models.transformer.layer_norm import LayerNorm
|
from funasr.models.transformer.layer_norm import LayerNorm
|
||||||
from funasr.models.rwkv_bat.rwkv_subsampling import RWKVConvInput
|
|
||||||
from funasr.models.transformer.utils.nets_utils import make_source_mask
|
from funasr.models.transformer.utils.nets_utils import make_source_mask
|
||||||
|
from funasr.models.rwkv_bat.rwkv_subsampling import RWKVConvInput
|
||||||
|
|
||||||
class RWKVEncoder(AbsEncoder):
|
|
||||||
|
@tables.register("encoder_classes", "RWKVEncoder")
|
||||||
|
class RWKVEncoder(torch.nn.Module):
|
||||||
"""RWKV encoder module.
|
"""RWKV encoder module.
|
||||||
|
|
||||||
Based on https://arxiv.org/pdf/2305.13048.pdf.
|
Based on https://arxiv.org/pdf/2305.13048.pdf.
|
||||||
@ -44,6 +47,7 @@ class RWKVEncoder(AbsEncoder):
|
|||||||
subsampling_factor: int =4,
|
subsampling_factor: int =4,
|
||||||
time_reduction_factor: int = 1,
|
time_reduction_factor: int = 1,
|
||||||
kernel: int = 3,
|
kernel: int = 3,
|
||||||
|
**kwargs,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Construct a RWKVEncoder object."""
|
"""Construct a RWKVEncoder object."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|||||||
@ -1,14 +1,10 @@
|
|||||||
"""Feed-forward (channel mixing) module for RWKV block.
|
#!/usr/bin/env python3
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
Based/Modified from https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v4/src/model.py
|
# Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved.
|
||||||
|
# MIT License (https://opensource.org/licenses/MIT)
|
||||||
Some variables are renamed according to https://github.com/huggingface/transformers/blob/main/src/transformers/models/rwkv/modeling_rwkv.py.
|
|
||||||
|
|
||||||
""" # noqa
|
|
||||||
|
|
||||||
from typing import List, Optional, Tuple
|
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
|
from typing import List, Optional, Tuple
|
||||||
|
|
||||||
|
|
||||||
class FeedForward(torch.nn.Module):
|
class FeedForward(torch.nn.Module):
|
||||||
|
|||||||
@ -1,19 +1,13 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
# Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved.
|
||||||
|
# MIT License (https://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
# Copyright 2019 Shigeki Karita
|
|
||||||
# Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
|
|
||||||
|
|
||||||
"""Subsampling layer definition."""
|
|
||||||
import numpy as np
|
|
||||||
import torch
|
|
||||||
import torch.nn.functional as F
|
|
||||||
from funasr.models.transformer.embedding import PositionalEncoding
|
|
||||||
import logging
|
|
||||||
from funasr.models.scama.utils import sequence_mask
|
|
||||||
from funasr.models.transformer.utils.nets_utils import sub_factor_to_params, pad_to_len
|
|
||||||
from typing import Optional, Tuple, Union
|
|
||||||
import math
|
import math
|
||||||
|
import torch
|
||||||
|
from typing import Optional, Tuple, Union
|
||||||
|
from funasr.models.transformer.utils.nets_utils import pad_to_len
|
||||||
|
|
||||||
|
|
||||||
class TooShortUttError(Exception):
|
class TooShortUttError(Exception):
|
||||||
"""Raised when the utt is too short for subsampling.
|
"""Raised when the utt is too short for subsampling.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user