offline mode for firewalled envs (#10407)

* offline mode start

* add specific values

* fix fallback

* add test

* better values check and range

* test that actually works

* document the offline mode

* Apply suggestions from code review

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>

* more strict check

* cleaner test

* pt-only test

* style

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
This commit is contained in:
Stas Bekman
2021-03-05 17:27:48 -08:00
committed by GitHub
parent 90ecc29656
commit 88a951e3cc
7 changed files with 111 additions and 5 deletions

View File

@@ -36,6 +36,7 @@ from .file_utils import (
ModelOutput,
cached_path,
hf_bucket_url,
is_offline_mode,
is_remote_url,
replace_return_docstrings,
)
@@ -964,6 +965,10 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin):
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