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

Size unmatched when running EAP-IG notebook #7

Closed
Miamm0v0 opened this issue Nov 19, 2024 · 5 comments
Closed

Size unmatched when running EAP-IG notebook #7

Miamm0v0 opened this issue Nov 19, 2024 · 5 comments
Labels
question Further information is requested

Comments

@Miamm0v0
Copy link

Miamm0v0 commented Nov 19, 2024

Hello!
Thank you very much for your outstanding work. I have encountered a question when I am trying to run EAP-IG notebook. I was running knowledge_eap.ipynb using gpt2-medium and found that
Activation Hook Error hook_embed torch.Size([1, 18, 1024]) torch.Size([1, 17, 1024]) 0 and
RuntimeError: The size of tensor a (18) must match the size of tensor b (17) at non-singleton dimension 1
I tried to solve the problem following #7 in EAP-IG but it didn't work.

@littlefive5
Copy link
Contributor

Can you provide your code and running examples?

@Miamm0v0
Copy link
Author

g = Graph.from_model(model)
start_time = time.time()
# Attribute using the model, graph, clean / corrupted data and labels, as well as a metric
attribute(model, g, data, partial(logit_diff, loss=True, mean=True), method='EAP-IG-case', ig_steps=100)
# attribute(model, g, data, partial(direct_logit, loss=True, mean=True), method='EAP-IG-case', ig_steps=30)
# attribute(model, g, dataloader, partial(logit_diff, loss=True, mean=True), method='EAP-IG', ig_steps=30)
g.apply_topn(5000, absolute=True)
g.prune_dead_nodes()

g.to_json('graph.json')

gz = g.to_graphviz()
gz.draw(f'graph.png', prog='dot')

end_time = time.time()
execution_time = end_time - start_time
print(f"程序执行时间:{execution_time}秒")

I was running the knowledge_eap.ipynb and all went well until I got to the block I mention above. and I got the output of
problem_circuits

@zxlzr zxlzr added the question Further information is requested label Nov 20, 2024
@littlefive5
Copy link
Contributor

littlefive5 commented Nov 26, 2024

Hello, sorry for being late.
This problem is due to the different lengths of the tokenized corrupted and clean subject tokens.
The tokenizers of GPT2 and LLAMA2 are different, making the case I used here unmatched. You can use different corrupted subjects to make sure the length is the same as Eiffel Tower such as the Santa Monica Beach.
I also enhance the assert here.

@zxlzr
Copy link
Contributor

zxlzr commented Nov 26, 2024

hi buddy, do you have any further questions?

@Miamm0v0
Copy link
Author

Hi!
Thank you very much for your assistance. I think I have no more questions so far and I'm gonna close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants