Skip to content
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

Name 'LearnedSourceLowRankRotatedSpaceIntervention' is not defined in tutorial notebook #132

Closed
Z1zs opened this issue Sep 3, 2024 · 1 comment
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@Z1zs
Copy link

Z1zs commented Sep 3, 2024

I tied to run this script(https://github.com/stanfordnlp/pyreft/blob/main/examples/memorisation/reft_power.ipynb) to figure out how reft should work, but got this error in "### Store with different access id":

TARGET_LAYER = 15

alice_access_id = "ALIC#ID1->"
model_max_length = 2048

# get tokenizer
tokenizer = transformers.AutoTokenizer.from_pretrained(
    model_name_or_path, model_max_length=model_max_length, 
    padding_side="right", use_fast=False)
tokenizer.pad_token = tokenizer.unk_token

# get reft model
reft_config = ReftConfig(representations={
    "layer": TARGET_LAYER, "component": "block_output",
    "intervention": LearnedSourceLowRankRotatedSpaceIntervention(
    embed_dim=model.config.hidden_size, 
    low_rank_dimension=1)})
reft_model = get_reft_model(model, reft_config)
reft_model.print_trainable_parameters()

# get training data and args
data_module = make_supervised_data_module(
    tokenizer, model, 
    [storage_access_id, alice_access_id], [memo_sequence, alice_slice])
training_args = transformers.TrainingArguments(output_dir="./tmp")
training_args.save_strategy = "no"
training_args.evaluation_strategy = "no"
training_args.num_train_epochs = 500.0
training_args.learning_rate = 8e-3
training_args.per_device_train_batch_size = 16
training_args.report_to = []
training_args.logging_steps = 100

# train
trainer = ReftTrainerForCausalLM(
    model=reft_model, tokenizer=tokenizer, args=training_args, **data_module)
_ = trainer.train()

NameError Traceback (most recent call last)
Cell In[28], line 15
10 tokenizer.pad_token = tokenizer.unk_token
12 # get reft model
13 reft_config = ReftConfig(representations={
14 "layer": TARGET_LAYER, "component": "block_output",
---> 15 "intervention": LearnedSourceLowRankRotatedSpaceIntervention(
16 embed_dim=model.config.hidden_size,
17 low_rank_dimension=1)})
18 reft_model = get_reft_model(model, reft_config)
19 reft_model.print_trainable_parameters()

NameError: name 'LearnedSourceLowRankRotatedSpaceIntervention' is not defined

I can't find or import 'LearnedSourceLowRankRotatedSpaceIntervention' in pyreft.
Should I replace the name 'LearnedSourceLowRankRotatedSpaceIntervention' with 'ConsreftIntervention'? What is the difference between these Intervention class?
(minor: 'storage_access_id' can also be not defined in this block.)

frankaging added a commit that referenced this issue Sep 3, 2024
[Minor] Update notebook with newer names (#132)
@frankaging
Copy link
Collaborator

@Z1zs Thanks for reporting the issue! I fixed the notebook. Please pull and retry.

And, yes - we renamed LearnedSourceLowRankRotatedSpaceIntervention to ConsreftIntervention (if you are curious, you could take a look at our commit history, etc..). I also corrected the "storage_access_id" issue. Some of our notebooks are made before we did the major refactory, so they might be broken.

@frankaging frankaging self-assigned this Sep 3, 2024
@frankaging frankaging added bug Something isn't working question Further information is requested labels Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants