Optimize CPU featurization pipeline: 37% speedup#283
Open
longleo17 wants to merge 1 commit intobytedance:mainfrom
Open
Optimize CPU featurization pipeline: 37% speedup#283longleo17 wants to merge 1 commit intobytedance:mainfrom
longleo17 wants to merge 1 commit intobytedance:mainfrom
Conversation
Key optimizations: - Featurizer.encoder: replace manual one-hot dict with torch.nn.functional.one_hot - ref_atom_name_chars_encoded: vectorized ASCII encoding via numpy frombuffer + one_hot - Template featurizer: pre-allocate numpy arrays instead of list append + np.stack - Template featurizer: reuse shared DistogramFeaturesConfig instance - Template parser: vectorized numpy operations for coordinate extraction - Template utils: batch numpy operations for atom mask and position computation - Dataset: replace df.apply(lambda) with df.isin() for eval_type filtering Benchmarked on template+MSA heavy workloads: ~37% wall-clock reduction in CPU featurization time, measured end-to-end on representative PDB complexes.
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.
This PR accelerates the data pipeline, a CPU bottleneck in current workflows
Summary
torch.nn.functional.one_hot, eliminating per-call dict comprehension overheadref_atom_name_chars_encodedusingnumpy.frombufferon ASCII bytes +F.one_hot, replacing nested Python loops over charactersnp.stack; reuse a sharedDistogramFeaturesConfiginstance across templatesdf.apply(lambda x: x in set)with vectorizeddf.isin()for eval_type filteringBenchmark results
Measured end-to-end on representative PDB complexes with template+MSA workloads:
Files changed
protenix/data/core/featurizer.pyprotenix/data/template/template_featurizer.pyprotenix/data/template/template_parser.pyprotenix/data/template/template_utils.pyprotenix/data/pipeline/dataset.py