-
Notifications
You must be signed in to change notification settings - Fork 14
perf(inference): drop training-only targets the inference forward never reads #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shenoynikhil
merged 3 commits into
recursionpharma:main
from
mooreneural:perf/skip-unused-inference-features
Aug 4, 2026
+118
−40
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| """Inference featurization emits exactly the expected set of features. | ||
|
|
||
| The forward pass never reads ``disto_target`` or ``token_to_rep_atom`` (the | ||
| ground-truth distogram label and the token-to-representative-atom gather | ||
| inherited from the Boltz training featurizer). Since the codebase is | ||
| inference-only, those tensors are not built at all. | ||
|
|
||
| Asserting the exact key set (rather than only the absence of those two) makes | ||
| this a contract on the featurizer output: adding or dropping any feature without | ||
| updating ``EXPECTED_FEATURE_KEYS`` fails here. Ligand-only input keeps this | ||
| CCD-free so it runs on plain CI. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from numpy.random import RandomState | ||
|
|
||
| from nesso.data.featurizer import NessoFeaturizer | ||
| from nesso.data.inference import InferenceDataset | ||
| from nesso.data.tokenize import tokenize_structure | ||
| from nesso.data.types import Manifest, Structure, Tokenized | ||
| from nesso.data.yaml_input import parse_yaml | ||
|
|
||
| # The complete set of tensors `NessoFeaturizer.process` is expected to return. | ||
| EXPECTED_FEATURE_KEYS = frozenset( | ||
| { | ||
| # token-level | ||
| "asym_id", | ||
| "entity_id", | ||
| "mol_type", | ||
| "pocket_feature", | ||
| "res_type", | ||
| "residue_index", | ||
| "sym_id", | ||
| "token_bonds", | ||
| "token_disto_mask", | ||
| "token_index", | ||
| "token_pad_mask", | ||
| "type_bonds", | ||
| # atom-level | ||
| "atom_pad_mask", | ||
| "atom_resolved_mask", | ||
| "atom_to_token", | ||
| "coords", | ||
| "ref_atom_name_chars", | ||
| "ref_charge", | ||
| "ref_chirality", | ||
| "ref_element", | ||
| "ref_hybridization", | ||
| "ref_pos", | ||
| "ref_space_uid", | ||
| # sequence embedding | ||
| "s_esm", | ||
| } | ||
| ) | ||
|
|
||
| _LIGAND_SMILES = "Cc1ccc(NC(=O)c2ccc(CN3CCN(C)CC3)cc2)cc1Nc1nccc(-c2cccnc2)n1" | ||
| _YAML = ( | ||
| "version: 1\n" | ||
| "sequences:\n" | ||
| " - ligand:\n" | ||
| " id: B\n" | ||
| f' smiles: "{_LIGAND_SMILES}"\n' | ||
| ) | ||
|
|
||
|
|
||
| def _raw_features(tmp_path: Path) -> dict: | ||
| """Exactly what ``NessoFeaturizer.process`` returns.""" | ||
| mol_dir = tmp_path / "rdkit_conformers" | ||
| structures_dir = tmp_path / "structures" | ||
| esm_dir = tmp_path / "esm" | ||
| for d in (mol_dir, structures_dir, esm_dir): | ||
| d.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| yaml_path = tmp_path / "lig.yaml" | ||
| yaml_path.write_text(_YAML) | ||
| struct, record, _, _ = parse_yaml( | ||
| yaml_path, mol_dir, ccd_dict=None, record_id="lig" | ||
| ) | ||
| struct.dump(structures_dir / f"{record.id}.npz") | ||
|
|
||
| struct = Structure.load(structures_dir / f"{record.id}.npz") | ||
| struct = struct.remove_invalid_chains(struct.mask.copy()) | ||
| tokens, bonds = tokenize_structure(struct) | ||
| tokenized = Tokenized(tokens=tokens, bonds=bonds, structure=struct, record=record) | ||
|
|
||
| ds = InferenceDataset( | ||
| manifest=Manifest([record]), | ||
| target_dir=tmp_path, | ||
| featurizer=NessoFeaturizer( | ||
| esm_emb_dir=esm_dir, esm_emb_dim=1280, esm_num_layers=33 | ||
| ), | ||
| ligand_dir=mol_dir, | ||
| ccd_pkl=None, | ||
| ) | ||
| return ds.featurizer.process( | ||
| tokenized, | ||
| record=record, | ||
| molecules=ds._setup_molecules(struct, str(record.id)), | ||
| random=RandomState(0), | ||
| atoms_per_window_queries=32, | ||
| binder_pocket_conditioned_prop=0.0, | ||
| max_tokens=None, | ||
| ) | ||
|
|
||
|
|
||
| def test_featurizer_emits_expected_keys(tmp_path: Path) -> None: | ||
| """The featurizer output must match the expected feature set exactly.""" | ||
| keys = set(_raw_features(tmp_path)) | ||
|
|
||
| missing = EXPECTED_FEATURE_KEYS - keys | ||
| unexpected = keys - EXPECTED_FEATURE_KEYS | ||
| assert not missing, f"missing expected features: {sorted(missing)}" | ||
| assert not unexpected, f"unexpected features: {sorted(unexpected)}" |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.