fix(loading): forward download_config to LocalEvaluationModuleFactory for local paths#760
Open
xodn348 wants to merge 1 commit into
Open
Conversation
… for local paths Previously, both branches of evaluation_module_factory that resolve a local .py file or directory omitted download_config when constructing LocalEvaluationModuleFactory. This caused the factory to fall back to a default DownloadConfig(), silently ignoring caller-supplied settings such as local_files_only, cache_dir, or use_etag — making it impossible to prevent outbound network access when loading local evaluation modules. Fixes huggingface#709
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
evaluation_module_factoryhas two branches that resolve a local script path — one for a bare.pyfile and one for a directory containing a same-named script. In both cases the function constructsLocalEvaluationModuleFactorywithout forwarding the caller-supplieddownload_config. The factory then falls back to a freshDownloadConfig(), silently discarding any settings the caller passed (e.g.local_files_only=True, a customcache_dir, oruse_etag=False). This makes it impossible to prevent outbound network requests when loading local evaluation modules in air-gapped or restricted-network environments, because the_download_additional_modulespath inside the factory always receives default download behaviour regardless of what the caller specified.The fix is a one-liner (×2): add
download_config=download_configto eachLocalEvaluationModuleFactory(...)call at lines 619–621 and 625–627 ofsrc/evaluate/loading.py. The non-local (Hub, cached) branches already passdownload_configcorrectly; this aligns the local branches with them.Two regression tests are added to
tests/test_load.pythat verifydownload_configis forwarded for both the.py-file path and the directory path. They usemock.patchto intercept the factory constructor call and assert thedownload_configkwarg matches the caller-supplied object.Issue
Fixes #709
Local verification
Risk
The change is minimal — two
download_config=download_configkeyword arguments added to existingLocalEvaluationModuleFactoryconstructor calls. The parameter was already defined on the constructor with a safe default (DownloadConfig()), so passing it explicitly cannot break any existing behaviour: callers that previously got the default will now get exactly the same default (since the top-levelevaluation_module_factoryalready initialisesdownload_config = DownloadConfig(**download_kwargs)when none is supplied). The only callers affected are those who explicitly pass a non-defaultDownloadConfigtoevaluation_module_factorywith a local path — those callers previously had their config silently dropped; now it is respected.