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

work in progress about fusion layer #2

Merged

Conversation

kwonjihun-theori
Copy link

@kwonjihun-theori kwonjihun-theori commented Apr 30, 2024

I attempted to implement the fusion layer. Although it seems to have been implemented plausibly, the result only generates meaningless tokens, and the logits values from model(**inputs) contain only NaN values.
As far as I know, memory usage should increase a little after fusing, but I haven't observed any increase in memory usage either.

It seems like something is wrong, but it might be a minor issue like when I implemented quantize before. Although it's still incomplete, I thought it might be helpful, so I'm submitting a PR.

I'm not sure if this process is possible, but I have enough hardware to conduct tests. If you modify the code, I can test it.

I would also like to contribute to this AutoAWQ project.

@TechxGenus
Copy link
Owner

Thanks for the commit. The framework is correct and should work after some modifications.

qkv_layer,
o_proj,
dev=dev,
max_seq_len=max_seq_len,
Copy link
Owner

Choose a reason for hiding this comment

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

Its RoPE implementation is different from Llama's. Require some modifications in attn.py to get everything working properly.

Copy link
Author

Choose a reason for hiding this comment

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

ok others edit is done.

I will edit attn.py!

Copy link
Author

Choose a reason for hiding this comment

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

I think this is too difficult task for me.

First, I checked the difference in the implementation of rotary posembedding between cohere and llama.

llama is just torch.cat after frequs operation, and cohere is torch.repeat_interleave.

Also, when llama proceeds with rotary_half
x1 = x[..., : x.shape[-1] // 2]
x2 = x[..., x.shape[-1] // 2 :]

to proceed,

cohere is
x1 = x[...,::2]
x2 = x[..., 1::2]

There is a difference in that.

However, I'm not sure how this should work with RoPE in awq.

Can I get any ideas or hints?

Copy link
Owner

Choose a reason for hiding this comment

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

Aha, I think using a staggered rope should be fine. Now I have device to modify it.

module.self_attn.k_proj,
module.self_attn.v_proj,
)
norm_1 = FasterTransformerRMSNorm(
Copy link
Owner

Choose a reason for hiding this comment

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

It use normal layernorm

norm_1 = module.input_layernorm

)

h = hidden_states.to(attn_output.device) + attn_output
out = h + self.mlp.forward(h)
Copy link
Owner

Choose a reason for hiding this comment

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

out = h + self.mlp.forward(norm_out)

@TechxGenus
Copy link
Owner

Thanks!

@TechxGenus TechxGenus merged commit d9f1d18 into TechxGenus:add_cohere_support May 23, 2024
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.

2 participants