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

Replace assertions with RuntimeError exceptions #14186

Merged
merged 1 commit into from
Oct 28, 2021
Merged
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
35 changes: 20 additions & 15 deletions src/transformers/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,10 @@ class TensorBoardCallback(TrainerCallback):

def __init__(self, tb_writer=None):
has_tensorboard = is_tensorboard_available()
assert (
has_tensorboard
), "TensorBoardCallback requires tensorboard to be installed. Either update your PyTorch version or install tensorboardX."
if not has_tensorboard:
raise RuntimeError(
"TensorBoardCallback requires tensorboard to be installed. Either update your PyTorch version or install tensorboardX."
)
if has_tensorboard:
try:
from torch.utils.tensorboard import SummaryWriter # noqa: F401
Expand Down Expand Up @@ -465,7 +466,8 @@ class WandbCallback(TrainerCallback):

def __init__(self):
has_wandb = is_wandb_available()
assert has_wandb, "WandbCallback requires wandb to be installed. Run `pip install wandb`."
if not has_wandb:
raise RuntimeError("WandbCallback requires wandb to be installed. Run `pip install wandb`.")
if has_wandb:
import wandb

Expand Down Expand Up @@ -587,7 +589,8 @@ class CometCallback(TrainerCallback):
"""

def __init__(self):
assert _has_comet, "CometCallback requires comet-ml to be installed. Run `pip install comet-ml`."
if not _has_comet:
raise RuntimeError("CometCallback requires comet-ml to be installed. Run `pip install comet-ml`.")
self._initialized = False

def setup(self, args, state, model):
Expand Down Expand Up @@ -643,9 +646,8 @@ class AzureMLCallback(TrainerCallback):
"""

def __init__(self, azureml_run=None):
assert (
is_azureml_available()
), "AzureMLCallback requires azureml to be installed. Run `pip install azureml-sdk`."
if not is_azureml_available():
raise RuntimeError("AzureMLCallback requires azureml to be installed. Run `pip install azureml-sdk`.")
self.azureml_run = azureml_run

def on_init_end(self, args, state, control, **kwargs):
Expand All @@ -667,7 +669,8 @@ class MLflowCallback(TrainerCallback):
"""

def __init__(self):
assert is_mlflow_available(), "MLflowCallback requires mlflow to be installed. Run `pip install mlflow`."
if not is_mlflow_available():
raise RuntimeError("MLflowCallback requires mlflow to be installed. Run `pip install mlflow`.")
import mlflow

self._MAX_PARAM_VAL_LENGTH = mlflow.utils.validation.MAX_PARAM_VAL_LENGTH
Expand Down Expand Up @@ -753,9 +756,10 @@ class NeptuneCallback(TrainerCallback):
"""

def __init__(self):
assert (
is_neptune_available()
), "NeptuneCallback requires neptune-client to be installed. Run `pip install neptune-client`."
if not is_neptune_available():
raise ValueError(
"NeptuneCallback requires neptune-client to be installed. Run `pip install neptune-client`."
)
import neptune.new as neptune

self._neptune = neptune
Expand Down Expand Up @@ -823,9 +827,10 @@ class CodeCarbonCallback(TrainerCallback):
"""

def __init__(self):
assert (
is_codecarbon_available()
), "CodeCarbonCallback requires `codecarbon` to be installed. Run `pip install codecarbon`."
if not is_codecarbon_available():
raise RuntimeError(
"CodeCarbonCallback requires `codecarbon` to be installed. Run `pip install codecarbon`."
)
import codecarbon

self._codecarbon = codecarbon
Expand Down