Skip to content

Manual intervene on sequence#184

Merged
karinazad merged 15 commits intoprescient-design:mainfrom
etherealsunshine:manual_intervene_on_sequence
Sep 10, 2025
Merged

Manual intervene on sequence#184
karinazad merged 15 commits intoprescient-design:mainfrom
etherealsunshine:manual_intervene_on_sequence

Conversation

@etherealsunshine
Copy link
Contributor

Description

Added capability to set indices for mutation in intervene_on_sequences in CBMPMLM. Addresses #182.

Behavior

If manual_positions is None → keep current attribution-based masking.

If manual_positions is provided:

Skip attribution computation entirely.
Create a (B, L) boolean mask with True at those positions for all sequences in the batch.
Pass that mask to ._mask_inputs so CLS/EOS/PAD are automatically excluded.
Proceed with existing concept override and sequence regeneration logic.

Example Usage

model.intervene_on_sequences(
    sequences=["MKTVRQERLK..."],
    concept="hydrophobicity",
    edits=3,
    intervention_type="positive",
    manual_positions=[10, 25, 33]  # direct token indices to mask
)

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Performance improvement
  • Code refactoring

concept: str,
edits: int,
intervention_type: str,
manual_positions: list[int] | None = None, # <-- added arg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add some tests for this new feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of right now, it allows for negative indexing because I thought I'd keep it in line with Pythonic features. Is that okay?

@etherealsunshine
Copy link
Contributor Author

Also while working on this, I thought it'd be useful for us if the intervene_on_sequence function also returns a list of gradient selected indices to mutate (something like Selected positions: [5, 12, 20]). Thoughts on this feature and would it be okay to add it(with the tests)? Thanks!

@karinazad
Copy link
Collaborator

this looks good to me. happy to approve - can you please make sure the UME changes from the MPS PR are not merged here?

@etherealsunshine
Copy link
Contributor Author

hi @karinazad, just made those changes, should be good to merge now!

@karinazad karinazad merged commit 8ea26f5 into prescient-design:main Sep 10, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants