feat: compositional guided sampling (--composition_bias)#14
Closed
exopoiesis wants to merge 1 commit intodeepmodeling:mainfrom
Closed
feat: compositional guided sampling (--composition_bias)#14exopoiesis wants to merge 1 commit intodeepmodeling:mainfrom
exopoiesis wants to merge 1 commit intodeepmodeling:mainfrom
Conversation
Soft bias for atom-type logits during autoregressive decoding. Steers generation toward desired compositions without retraining. - parse_composition_bias() in elements.py: "Fe:2.0,S:1.5" -> array - composition_bias param in make_sample_crystal(): added to a_logit - --composition_bias CLI arg in main.py - 17 tests: parsing (13, incl. out-of-vocab regression) + sampling (4) Raise ValueError when element index exceeds atom_types vocabulary instead of silently dropping the bias entry. Usage: python main.py --composition_bias "Fe:2.0,S:1.5,O:-1.0" ... Ref: deepmodeling#13 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
|
Moving composition_bias to crystalformer-x per discussion in #13. Thanks for the guidance! |
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
Adds soft bias for atom-type logits during autoregressive decoding, steering generation toward desired compositions without retraining or fine-tuning.
This is the smallest self-contained piece from the discussion in #13. Instead of building a full screening pipeline into the core repo (which we agree would be out of scope), we extracted this single feature — it lives entirely within
src/and touches only 3 existing files.Motivation
When generating structures for a specific application (e.g., Fe-S sulfides for ionic conductors), most random generations contain irrelevant compositions. With composition bias, we increased our Fe-S hit rate from ~12% to ~60% — a 5x improvement in useful output with zero model changes.
This is useful for any targeted generation task: battery cathodes (bias Li, transition metals), thermoelectrics (bias Bi, Te), catalysts (bias Pt-group), etc.
How it works
At each atom-type sampling step, a user-provided bias vector is added to logits before softmax:
atom_maskstill overrides bias (hard block wins over soft nudge)Changes
crystalformer/src/elements.pyparse_composition_bias():"Fe:2.0,S:1.5"→ numpy arraycrystalformer/src/sample.pycomposition_biasparam inmake_sample_crystal()main.py--composition_biasCLI argumenttests/test_composition_bias.pyUsage
Tests
17 tests covering:
Design decisions
composition_bias=None(default) creates a zero vector, addition is a no-op in practiceCo-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com