-
Notifications
You must be signed in to change notification settings - Fork 125
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
[P1] Intervention Locations more than Prefix and Suffix #122
Comments
@comeandcode Hey, what is your intervenable model config? And could you give an example of the |
Thank you very much for your reply! Consider I am applying loreft to 3 layers: [3, 6, 9], and I create a list: |
@comeandcode Thanks. This should be a basic usecase of pyvene APIs. Did you set up your call like: # run intervened forward pass
unit_locations = None
if "intervention_locations" in inputs:
unit_locations={"sources->base": (
None,
inputs["intervention_locations"].permute(1, 0, 2).tolist()
)}
_, cf_outputs = intervenable(
{
"input_ids": inputs["input_ids"],
"attention_mask": inputs["attention_mask"]
},
unit_locations=unit_locations,
labels=inputs["labels"],
subspaces=inputs["subspaces"].permute(1, 0, 2).tolist() if "subspaces" in inputs else None
) The |
Thank you for your reply! Yes, I followed the example you kindly provided in Pyreft/example/loreft, since using multiple intervention locations (3 or more) on the same layer is supported by pyvene, I will try to find out if there are any other mistakes and if so I will post them here! By the way, I found in the example/loreft, special tokens were skipped such as BOS or EOS right? Since I printed out the intervention locations and found they started from 1 but 0. So that only real prompts are intervened instead of affecting special tokens. I am not sure if I am correct on this. Thank you! |
Hi, did you find out the reason ? Thanks! |
I found that if you use get_intervention_locations function in pyreft when the num_interventions is set as an odd number (like 5 or 7 ...) and share_weights is set as False, the length of intervention_locations you get will one less than the num_interventions you set. Take the code as below as an example:
The function will give you
instead of
or
This is due to the simple logic error in
If num_interventions is 5, then num_interventions//2 equals 2. This means [left_intervention_locations] and [right_intervention_locations] are each repeated 2 times, resulting in a list with only 4 elements instead of the expected 5. So you can change the function
or just avoid setting odd num_interventions. I struggled with this and found this error. Hope this can help you. |
Does the backbone pyvene support more than two intervention blocks on one layer? I met
anaconda3/envs/reft_train/lib/python3.10/site-packages/pyvene/models/intervenable_base.py", line 1092, in _wait_for_forward_with_parallel_intervention unit_locations_base[ IndexError: list index out of range
when I tried to add the third intervention block into one layer.The text was updated successfully, but these errors were encountered: