offline mode for firewalled envs (part 2) (#10569)

* more readable test

* add all the missing places

* one more nltk

* better exception check

* revert
This commit is contained in:
Stas Bekman
2021-03-08 08:52:20 -08:00
committed by GitHub
parent 5469369480
commit 6f84531e61
5 changed files with 42 additions and 6 deletions

View File

@@ -35,6 +35,7 @@ from .file_utils import (
cached_path,
hf_bucket_url,
is_flax_available,
is_offline_mode,
is_remote_url,
is_tf_available,
is_torch_available,
@@ -342,6 +343,10 @@ class PreTrainedFeatureExtractor:
local_files_only = kwargs.pop("local_files_only", False)
revision = kwargs.pop("revision", None)
if is_offline_mode() and not local_files_only:
logger.info("Offline mode: forcing local_files_only=True")
local_files_only = True
pretrained_model_name_or_path = str(pretrained_model_name_or_path)
if os.path.isdir(pretrained_model_name_or_path):
feature_extractor_file = os.path.join(pretrained_model_name_or_path, FEATURE_EXTRACTOR_NAME)

View File

@@ -1105,6 +1105,10 @@ def cached_path(
if isinstance(cache_dir, Path):
cache_dir = str(cache_dir)
if is_offline_mode() and not local_files_only:
logger.info("Offline mode: forcing local_files_only=True")
local_files_only = True
if is_remote_url(url_or_filename):
# URL, so get it from the cache (downloading if necessary)
output_path = get_from_cache(

View File

@@ -28,7 +28,7 @@ from flax.traverse_util import flatten_dict, unflatten_dict
from jax.random import PRNGKey
from .configuration_utils import PretrainedConfig
from .file_utils import FLAX_WEIGHTS_NAME, WEIGHTS_NAME, cached_path, hf_bucket_url, is_remote_url
from .file_utils import FLAX_WEIGHTS_NAME, WEIGHTS_NAME, cached_path, hf_bucket_url, is_offline_mode, is_remote_url
from .utils import logging
@@ -229,6 +229,10 @@ class FlaxPreTrainedModel(ABC):
use_auth_token = kwargs.pop("use_auth_token", None)
revision = kwargs.pop("revision", None)
if is_offline_mode() and not local_files_only:
logger.info("Offline mode: forcing local_files_only=True")
local_files_only = True
# Load config if we don't provide a configuration
if not isinstance(config, PretrainedConfig):
config_path = config if config is not None else pretrained_model_name_or_path

View File

@@ -36,6 +36,7 @@ from .file_utils import (
ModelOutput,
cached_path,
hf_bucket_url,
is_offline_mode,
is_remote_url,
)
from .generation_tf_utils import TFGenerationMixin
@@ -1151,6 +1152,10 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin, TFGenerationMixin):
revision = kwargs.pop("revision", None)
mirror = kwargs.pop("mirror", None)
if is_offline_mode() and not local_files_only:
logger.info("Offline mode: forcing local_files_only=True")
local_files_only = True
# Load config if we don't provide a configuration
if not isinstance(config, PretrainedConfig):
config_path = config if config is not None else pretrained_model_name_or_path