Unverified Commit 1496931b authored by Doug Blank's avatar Doug Blank Committed by GitHub
Browse files

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
parent 985bba90
...@@ -2,16 +2,24 @@ ...@@ -2,16 +2,24 @@
import math import math
import os import os
from .utils import logging
logger = logging.get_logger(__name__)
# Import 3rd-party integrations first: # Import 3rd-party integrations before ML frameworks:
try: try:
# Comet needs to be imported before any ML frameworks # Comet needs to be imported before any ML frameworks
import comet_ml # noqa: F401 import comet_ml # noqa: F401
# XXX: there should be comet_ml.ensure_configured(), like `wandb`, for now emulate it if comet_ml.config.get_config("comet.api_key"):
comet_ml.Experiment(project_name="ensure_configured")
_has_comet = True _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): except (ImportError, ValueError):
_has_comet = False _has_comet = False
...@@ -63,13 +71,9 @@ except ImportError: ...@@ -63,13 +71,9 @@ except ImportError:
# No transformer imports above this point # No transformer imports above this point
from .file_utils import is_torch_tpu_available from .file_utils import is_torch_tpu_available # noqa: E402
from .trainer_callback import TrainerCallback from .trainer_callback import TrainerCallback # noqa: E402
from .trainer_utils import PREFIX_CHECKPOINT_DIR, BestRun from .trainer_utils import PREFIX_CHECKPOINT_DIR, BestRun # noqa: E402
from .utils import logging
logger = logging.get_logger(__name__)
# Integration functions: # Integration functions:
......
...@@ -26,18 +26,9 @@ import warnings ...@@ -26,18 +26,9 @@ import warnings
from pathlib import Path from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Tuple, Union 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 # Integrations must be imported before ML frameworks:
from .file_utils import WEIGHTS_NAME, is_datasets_available, is_in_notebook, is_torch_tpu_available from .integrations import ( # isort: split
from .integrations import (
default_hp_search_backend, default_hp_search_backend,
hp_params, hp_params,
is_comet_available, is_comet_available,
...@@ -49,6 +40,18 @@ from .integrations import ( ...@@ -49,6 +40,18 @@ from .integrations import (
run_hp_search_optuna, run_hp_search_optuna,
run_hp_search_ray, 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_auto import MODEL_FOR_QUESTION_ANSWERING_MAPPING
from .modeling_utils import PreTrainedModel from .modeling_utils import PreTrainedModel
from .optimization import AdamW, get_linear_schedule_with_warmup from .optimization import AdamW, get_linear_schedule_with_warmup
......
...@@ -6,12 +6,18 @@ import os ...@@ -6,12 +6,18 @@ import os
import warnings import warnings
from typing import Callable, Dict, Optional, Tuple 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 numpy as np
import tensorflow as tf import tensorflow as tf
from packaging.version import parse from packaging.version import parse
from tensorflow.python.distribute.values import PerReplica from tensorflow.python.distribute.values import PerReplica
from .integrations import is_comet_available, is_wandb_available
from .modeling_tf_utils import TFPreTrainedModel from .modeling_tf_utils import TFPreTrainedModel
from .optimization_tf import GradientAccumulator, create_optimizer from .optimization_tf import GradientAccumulator, create_optimizer
from .trainer_utils import PREFIX_CHECKPOINT_DIR, EvalPrediction, PredictionOutput, set_seed from .trainer_utils import PREFIX_CHECKPOINT_DIR, EvalPrediction, PredictionOutput, set_seed
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment