fix: don't import datasets on the inference path#41
Open
emiliano-go wants to merge 1 commit into
Open
Conversation
Repoint two imports and package __init__.py so that 'import needle' and needle.model.run do not pull in the HuggingFace datasets library. All four symbols (get_tokenizer, to_snake_case, DEFAULT_MAX_ENC_LEN, DEFAULT_MAX_GEN_LEN) are defined in needle/dataset/tokenizer.py and were merely re-exported through needle/dataset/dataset.py. Changing the import source removes the unconditional from datasets import Dataset, load_from_disk at module level of dataset.py, which was the only thing tying the inference path to datasets (and its pyarrow/pandas/fsspec dependency tree). Needle/dataset/__init__.py also re-exported dataset.py via wildcard; removing that line is required because importing needle.dataset.tokenizer triggers package initialization, which previously loaded dataset.py. Signed-off-by: Emiliano Gandini Outeda <emiliano.gandini@protonmail.com>
emiliano-go
force-pushed
the
fix/remove-datasets-inference-import
branch
from
July 17, 2026 17:22
4eee41b to
b0b7926
Compare
Author
|
Removing from needle.dataset import SomeTrainingClasswill now get an Also, to make sure this heavy python -c "import sys; import needle; assert 'datasets' not in sys.modules, 'datasets leaked into inference path'"It's cheap (~100ms) and ensures the inference path stays lean indefinitely. I can add it in a separate commit or a follow-up PR, just lmk. |
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.
import needlepulled in HuggingFacedatasets(and itspyarrow/pandas/fsspectree) even though nothing on the inference path uses it. The tokenizer symbols thatrun.pyand__init__.pyneed are defined inneedle/dataset/tokenizer.pybut were being imported throughneedle/dataset/dataset.py, which importsdatasetsat module level.This repoints those imports at the module where the symbols are actually defined. Same objects, no API or dependency changes.
Closes #40
Changes
The third change is required, not cleanup.
needle/dataset/__init__.pyexecutes on anyneedle.dataset.*import, so it triggersdatasetsbeforetokenizer.pyis ever reached. Without it, the first two changes have no effect.Verification
needle.get_tokenizer,needle.generate,needle.load_checkpointall still resolveget_tokenizeris the same object as before (gt1 is gt2)from needle.dataset.dataset import ...still works;datasetsloads lazily when training code actually runsSafety
No internal consumer relies on the star re-export. All existing imports are either submodule imports (
from ..dataset import dataset as data_mod,from ..dataset import generate as gd) or submodule-qualified (from .dataset import ...), none of which are affected by removing it.