Improve gene vocabulary loading and torchtext compatibility - #354
Open
Evanescence0515 wants to merge 1 commit into
Open
Improve gene vocabulary loading and torchtext compatibility#354Evanescence0515 wants to merge 1 commit into
Evanescence0515 wants to merge 1 commit into
Conversation
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
This PR improves gene vocabulary loading performance and removes the direct
torchtextdependency from the integration fine-tuning example.It addresses the slow or apparently hanging vocabulary construction reported in #267 by replacing repeated token insertion with validated bulk initialization.
It also removes version-sensitive imports of
torchtext.vocab.Vocaband the privatetorchtext._torchtext.Vocabimplementation fromexamples/finetune_integration.py, related to the torchtext compatibility problem reported in #352.Related issues: #267, #352.
Problem
GeneVocab.from_dict()currently inserts tokens one at a time throughinsert_token().With the pure-Python
BuiltinVocabbackend, each insertion rebuilds the complete token-to-index mapping. Loading a vocabulary with approximately 60,000 tokens therefore has quadratic time complexity and can take more than one minute.In addition,
examples/finetune_integration.pydirectly importstorchtext.vocab.Vocaband the privatetorchtext._torchtext.Vocabimplementation. This can fail across differenttorchtextversions.Changes
_init_from_tokens()instead of repeatedly callinginsert_token().torchtextimports fromexamples/finetune_integration.py.GeneVocab.from_dict()when constructing a vocabulary without a pretrained model, preserving the original token order.Performance
Using the built-in vocabulary backend, a vocabulary containing 60,697 tokens was constructed in approximately:
Tests
The skipped tests require the optional torchtext dependency.
Additional formatting, syntax, and patch checks passed.