Skip to content
Open
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 funasr/bin/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import torch.distributed as dist

from omegaconf import DictConfig, OmegaConf
from torch.cuda.amp import autocast, GradScaler
from funasr.utils.amp import autocast, GradScaler
from torch.nn.parallel import DistributedDataParallel as DDP
from torch.distributed.fsdp import FullyShardedDataParallel as FSDP
from torch.distributed.algorithms.join import Join
Expand Down
2 changes: 1 addition & 1 deletion funasr/bin/train_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import torch.distributed as dist

from omegaconf import DictConfig, OmegaConf
from torch.cuda.amp import autocast, GradScaler
from funasr.utils.amp import autocast, GradScaler
from torch.nn.parallel import DistributedDataParallel as DDP
from torch.distributed.fsdp import FullyShardedDataParallel as FSDP
from torch.distributed.algorithms.join import Join
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/bat/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/bicif_paraformer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from funasr.train_utils.device_funcs import to_device

if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/campplus/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/contextual_paraformer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/ct_transformer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
except:
pass
if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/ct_transformer_streaming/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/data2vec/data2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from funasr.train_utils.device_funcs import force_gatherable

if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/e_paraformer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import copy
import torch
import logging
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
from typing import Union, Dict, List, Tuple, Optional

from funasr.register import tables
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/e_paraformer/pif_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from funasr.register import tables
from funasr.train_utils.device_funcs import to_device
from funasr.models.transformer.utils.nets_utils import make_pad_mask
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast


@tables.register("predictor_classes", "PifPredictor")
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/emotion2vec/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

logger = logging.getLogger(__name__)
if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/fsmn_kws/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
import torch
import logging
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
from typing import Union, Dict, List, Tuple, Optional

from funasr.register import tables
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/fsmn_kws_mt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
import torch
import logging
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
from typing import Union, Dict, List, Tuple, Optional

from funasr.register import tables
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/lcbnet/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import time
import torch
import torch.nn as nn
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast

from funasr.losses.label_smoothing_loss import LabelSmoothingLoss
from funasr.models.ctc.ctc import CTC
Expand Down
14 changes: 7 additions & 7 deletions funasr/models/llm_asr/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
import re
from funasr.models.scama.utils import sequence_mask
from funasr.losses.label_smoothing_loss import LabelSmoothingLoss
Expand Down Expand Up @@ -583,7 +583,7 @@ def forward(

batch_size, frames, _ = speech.shape

with torch.cuda.amp.autocast(enabled=False):
with autocast(enabled=False):
# audio encoder
encoder_out, encoder_out_lens = self.encode(speech, speech_lengths)

Expand Down Expand Up @@ -618,7 +618,7 @@ def forward(
batch_idx, :min_len, :
]

with torch.cuda.amp.autocast(
with autocast(
enabled=True if self.llm_dtype != "fp32" else False, dtype=dtype_map[self.llm_dtype]
):
labels_ids[labels_ids == -1] = -100
Expand Down Expand Up @@ -883,7 +883,7 @@ def inference(
llm_dtype = "fp16" if kwargs.get("fp16", False) else llm_dtype
llm_dtype = "bf16" if kwargs.get("bf16", False) else llm_dtype

with torch.cuda.amp.autocast(
with autocast(
enabled=True if llm_dtype != "fp32" else False, dtype=dtype_map[llm_dtype]
):
label = contents["assistant"][0]
Expand Down Expand Up @@ -1159,7 +1159,7 @@ def forward(
batch_size_speech, frames, _ = speech.shape
batch_size, token_num = input_ids.shape

with torch.cuda.amp.autocast(enabled=False):
with autocast(enabled=False):
# audio encoder
encoder_out, encoder_out_lens = self.encode(speech, speech_lengths)

Expand Down Expand Up @@ -1203,7 +1203,7 @@ def forward(

speech_idx += 1

with torch.cuda.amp.autocast(
with autocast(
enabled=True if self.llm_dtype != "fp32" else False, dtype=dtype_map[self.llm_dtype]
):
labels_ids[labels_ids == -1] = -100
Expand Down Expand Up @@ -1551,7 +1551,7 @@ def inference(
llm_dtype = "fp16" if kwargs.get("fp16", False) else llm_dtype
llm_dtype = "bf16" if kwargs.get("bf16", False) else llm_dtype

with torch.cuda.amp.autocast(
with autocast(
enabled=True if llm_dtype != "fp32" else False, dtype=dtype_map[llm_dtype]
):
label = contents["assistant"][-1]
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/llm_asr_nar/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast

from funasr.models.scama.utils import sequence_mask
from funasr.losses.label_smoothing_loss import LabelSmoothingLoss
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/mfcca/e2e_asr_mfcca.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from funasr.models.base_model import FunASRModel

if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/monotonic_aligner/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
import copy
import torch
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
from typing import Union, Dict, List, Tuple, Optional

from funasr.register import tables
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/paraformer/cif_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from funasr.register import tables
from funasr.train_utils.device_funcs import to_device
from funasr.models.transformer.utils.nets_utils import make_pad_mask
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast


@tables.register("predictor_classes", "CifPredictor")
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/paraformer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import copy
import torch
import logging
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
from typing import Union, Dict, List, Tuple, Optional

from funasr.register import tables
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/paraformer_streaming/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/paraformer_v2_community/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import copy
import torch
import logging
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
from typing import Union, Dict, List, Tuple, Optional

from funasr.register import tables
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/sa_asr/e2e_sa_asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from funasr.models.base_model import FunASRModel

if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/sanm_kws/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
import torch
import logging
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
from typing import Union, Dict, List, Tuple, Optional

from funasr.register import tables
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/sanm_kws_streaming/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/scama/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from funasr.models.scama.utils import sequence_mask

if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/seaco_paraformer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/sense_voice/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import torch.nn.functional as F
from torch import Tensor
from torch import nn
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
from funasr.metrics.compute_acc import compute_accuracy, th_accuracy
from funasr.losses.label_smoothing_loss import LabelSmoothingLoss
from funasr.train_utils.device_funcs import force_gatherable
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/sond/e2e_diar_sond.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from funasr.utils.hinter import hint_once

if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/transducer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/transformer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
import torch
import torch.nn as nn
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast

from funasr.losses.label_smoothing_loss import LabelSmoothingLoss
from funasr.models.ctc.ctc import CTC
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/uniasr/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
import torch
import logging
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
from typing import Union, Dict, List, Tuple, Optional

from funasr.register import tables
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/whisper_lid/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch
import numpy as np
import torch.nn as nn
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast

from funasr.losses.label_smoothing_loss import LabelSmoothingLoss
from funasr.models.ctc.ctc import CTC
Expand Down
2 changes: 1 addition & 1 deletion funasr/models/xvector/e2e_sv.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from funasr.models.base_model import FunASRModel

if LooseVersion(torch.__version__) >= LooseVersion("1.6.0"):
from torch.cuda.amp import autocast
from funasr.utils.amp import autocast
else:
# Nothing to do if torch<1.6.0
@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion funasr/train_utils/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tqdm import tqdm
from datetime import datetime
import torch.distributed as dist
from torch.cuda.amp import autocast, GradScaler
from funasr.utils.amp import autocast, GradScaler
from contextlib import nullcontext, contextmanager
from pathlib import Path

Expand Down
4 changes: 2 additions & 2 deletions funasr/train_utils/trainer_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tqdm import tqdm
from datetime import datetime
import torch.distributed as dist
from torch.cuda.amp import autocast, GradScaler
from funasr.utils.amp import autocast, GradScaler
from contextlib import nullcontext, contextmanager
from pathlib import Path
from torch.nn.parallel import DistributedDataParallel as DDP
Expand All @@ -32,7 +32,7 @@ def maybe_autocast(dtype=None, use_deepspeed=False):
use_deepspeed: TODO.
"""
if use_deepspeed:
with torch.cuda.amp.autocast(enabled=True, dtype=dtype, cache_enabled=False):
with autocast(enabled=True, dtype=dtype, cache_enabled=False):
yield
else:
if dtype == torch.float16 or dtype == torch.bfloat16:
Expand Down
Loading