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

nnf_multi_head_attention_forward (indices) #1133

Closed
AGPatriota opened this issue Jan 31, 2024 · 1 comment · Fixed by #1154
Closed

nnf_multi_head_attention_forward (indices) #1133

AGPatriota opened this issue Jan 31, 2024 · 1 comment · Fixed by #1154

Comments

@AGPatriota
Copy link

AGPatriota commented Jan 31, 2024

Dear fellows,

Can you please verify whether the following piece of code is correct:

 if (!is.null(in_proj_bias)) {
       q <- nnf_linear(query, q_proj_weight, in_proj_bias[1:embed_dim])
       k <- nnf_linear(key, k_proj_weight, in_proj_bias[embed_dim:(embed_dim * 2)])
       v <- nnf_linear(value, v_proj_weight, in_proj_bias[(embed_dim * 2):N])

link
Should'nt it be the following:

if (!is.null(in_proj_bias)) {
      q <- nnf_linear(query, q_proj_weight, in_proj_bias[1:embed_dim])
      k <- nnf_linear(key, k_proj_weight, in_proj_bias[(embed_dim+1):(embed_dim * 2)])
      v <- nnf_linear(value, v_proj_weight, in_proj_bias[(embed_dim * 2+1):N])

Also, I did not find where N is defined in the code.

In Python, the code is:

   if in_proj_bias is not None:
             q = linear(query, q_proj_weight_non_opt, in_proj_bias[0:embed_dim])
             k = linear(key, k_proj_weight_non_opt, in_proj_bias[embed_dim:(embed_dim * 2)])
             v = linear(value, v_proj_weight_non_opt, in_proj_bias[(embed_dim * 2):])

which is correct.

Thanks

@cregouby
Copy link
Contributor

cregouby commented May 10, 2024

Hello @AGPatriota
N in {torch} is a build-in for last(), an equivalent of the python negative index -1.

You are correct with the mistake in translating pytorch idx into R {torch} indices. I'll propose a fix.

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 a pull request may close this issue.

2 participants