Fix comet_ml import and add ensure availability (#7933)
* Fix comet_ml import and add ensure availability * Make isort happy * Make flake8 happy * Don't show comet_ml warn if COMET_MODE=DISABLED * Make isort happy
This commit is contained in:
@@ -2,16 +2,24 @@
|
||||
import math
|
||||
import os
|
||||
|
||||
from .utils import logging
|
||||
|
||||
# Import 3rd-party integrations first:
|
||||
|
||||
logger = logging.get_logger(__name__)
|
||||
|
||||
|
||||
# Import 3rd-party integrations before ML frameworks:
|
||||
|
||||
try:
|
||||
# Comet needs to be imported before any ML frameworks
|
||||
import comet_ml # noqa: F401
|
||||
|
||||
# XXX: there should be comet_ml.ensure_configured(), like `wandb`, for now emulate it
|
||||
comet_ml.Experiment(project_name="ensure_configured")
|
||||
_has_comet = True
|
||||
if comet_ml.config.get_config("comet.api_key"):
|
||||
_has_comet = True
|
||||
else:
|
||||
if os.getenv("COMET_MODE", "").upper() != "DISABLED":
|
||||
logger.warning("comet_ml is installed but `COMET_API_KEY` is not set.")
|
||||
_has_comet = False
|
||||
except (ImportError, ValueError):
|
||||
_has_comet = False
|
||||
|
||||
@@ -63,13 +71,9 @@ except ImportError:
|
||||
|
||||
# No transformer imports above this point
|
||||
|
||||
from .file_utils import is_torch_tpu_available
|
||||
from .trainer_callback import TrainerCallback
|
||||
from .trainer_utils import PREFIX_CHECKPOINT_DIR, BestRun
|
||||
from .utils import logging
|
||||
|
||||
|
||||
logger = logging.get_logger(__name__)
|
||||
from .file_utils import is_torch_tpu_available # noqa: E402
|
||||
from .trainer_callback import TrainerCallback # noqa: E402
|
||||
from .trainer_utils import PREFIX_CHECKPOINT_DIR, BestRun # noqa: E402
|
||||
|
||||
|
||||
# Integration functions:
|
||||
|
||||
@@ -26,18 +26,9 @@ import warnings
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
from packaging import version
|
||||
from torch import nn
|
||||
from torch.utils.data.dataloader import DataLoader
|
||||
from torch.utils.data.dataset import Dataset
|
||||
from torch.utils.data.distributed import DistributedSampler
|
||||
from torch.utils.data.sampler import RandomSampler, SequentialSampler
|
||||
|
||||
from .data.data_collator import DataCollator, DataCollatorWithPadding, default_data_collator
|
||||
from .file_utils import WEIGHTS_NAME, is_datasets_available, is_in_notebook, is_torch_tpu_available
|
||||
from .integrations import (
|
||||
# Integrations must be imported before ML frameworks:
|
||||
from .integrations import ( # isort: split
|
||||
default_hp_search_backend,
|
||||
hp_params,
|
||||
is_comet_available,
|
||||
@@ -49,6 +40,18 @@ from .integrations import (
|
||||
run_hp_search_optuna,
|
||||
run_hp_search_ray,
|
||||
)
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
from packaging import version
|
||||
from torch import nn
|
||||
from torch.utils.data.dataloader import DataLoader
|
||||
from torch.utils.data.dataset import Dataset
|
||||
from torch.utils.data.distributed import DistributedSampler
|
||||
from torch.utils.data.sampler import RandomSampler, SequentialSampler
|
||||
|
||||
from .data.data_collator import DataCollator, DataCollatorWithPadding, default_data_collator
|
||||
from .file_utils import WEIGHTS_NAME, is_datasets_available, is_in_notebook, is_torch_tpu_available
|
||||
from .modeling_auto import MODEL_FOR_QUESTION_ANSWERING_MAPPING
|
||||
from .modeling_utils import PreTrainedModel
|
||||
from .optimization import AdamW, get_linear_schedule_with_warmup
|
||||
|
||||
@@ -6,12 +6,18 @@ import os
|
||||
import warnings
|
||||
from typing import Callable, Dict, Optional, Tuple
|
||||
|
||||
|
||||
# Integrations must be imported before ML frameworks:
|
||||
from .integrations import ( # isort: split
|
||||
is_comet_available,
|
||||
is_wandb_available,
|
||||
)
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from packaging.version import parse
|
||||
from tensorflow.python.distribute.values import PerReplica
|
||||
|
||||
from .integrations import is_comet_available, is_wandb_available
|
||||
from .modeling_tf_utils import TFPreTrainedModel
|
||||
from .optimization_tf import GradientAccumulator, create_optimizer
|
||||
from .trainer_utils import PREFIX_CHECKPOINT_DIR, EvalPrediction, PredictionOutput, set_seed
|
||||
|
||||
Reference in New Issue
Block a user