Skip to content

Conversation

jacobthebanana
Copy link

[NLP] Add llm.c request encoder kernel reference

Type of Change

  • New Pocket Reference
  • Edit to Existing Pocket Reference
  • Other (please describe):

Fixes #

Book

  • fundamentals
  • nlp
  • cv
  • rl
  • fl
  • responsible_ai

Description

Add LLM.C encoder forwarder references.

Checklist

  • I have included appropriate contributor tags ({{#author}} or {{#authors}})
  • I have added the reading time preprocessor tag under the title
  • Content is concise and within 7 minutes reading time
  • I have included relevant references and further reading links
  • I have tested locally using mdbook watch books/<book-name> --open
  • Pre-commit hooks pass without errors
  • I have linked to related issues

Additional Context

CUDA Club

@jacobthebanana jacobthebanana self-assigned this Apr 4, 2025
@jacobthebanana jacobthebanana requested review from nerdai and xeon27 April 4, 2025 15:28
@nerdai
Copy link
Collaborator

nerdai commented Apr 4, 2025

@jacobthebanana can you kindly sync your local repo and force push the commit after?

@nerdai nerdai force-pushed the 91-new-request-encoder-kernel branch from e6876be to d204529 Compare April 10, 2025 13:07
@nerdai
Copy link
Collaborator

nerdai commented Apr 10, 2025

Hi @jacobthebanana,

I had to clean up your PR quite a bit, and in doing so, I hope I didn't modify the core of your contribution, namely your encoder_forward.md pocket ref.

Here's what I had to do:

  1. resolve conflicts — your PR contained more than your contributed pocket ref. I suspect that you were probably branch was created off an out-of-date base. In future, before contributing your new pocket ref, please do (i) update your local main branch; (ii) create your new dev branch from this in-sync main branch

  2. lint — we have linters to ensure the markdown is formatted nicely as well as doesn't contain any syntactical errors (though not all are caught by the linters). In future please do make lint and address any linting issues in your PR in order to get the checks to pass.

  3. Finally, I also added your Github user instead of the placeholder VectorInstitute

Copy link
Collaborator

@nerdai nerdai Apr 10, 2025

Choose a reason for hiding this comment

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

nit but can we change the title to "# Forward Pass Kernels of Positional Embeddings within GPT-2"

can be proceessed with the remainder of the transformer blocks:

- Input:
- "input" `inp`, produced by the tokenizer- An integer array of shape $(B,\, T)$,
Copy link
Collaborator

Choose a reason for hiding this comment

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

in-line math in the mdbook's render of markdown math doesn't use single "$" as delimeters. Rather it uses '\( \)'. Please replace this and all instances of '$ ... $' with '\( ... \)'

Copy link
Collaborator

@nerdai nerdai left a comment

Choose a reason for hiding this comment

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

Thanks @jacobthebanana for the pocket ref contribution! After cleaning up your PR, I was able to make a first pass at reviewing the core content. Left a few comments


#### References

1. Code for encoder forward kernels from [llm.c](https://github.com/karpathy/llm.c/blob/master/dev/cuda/encoder_forward.cu)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please also change this to MLA style

[_Karpathy, Andrej. "encoder_forward.cu." llm.c, GitHub, accessed 10 Apr. 2025, github.com/karpathy/llm.c/blob/master/dev/cuda/encoder_forward.cu._](https://github.com/karpathy/llm.c/blob/master/dev/cuda/encoder_forward.cu)

@nerdai nerdai requested a review from Viky397 April 14, 2025 13:35
this feature to make processing a lot more efficient.

While in the kernel, the additions are defined in a for-loop across the $\texttt{x128::size}$,
one floating point number at a time, the kernel uses `#pragma unroll` to automatically
Copy link

@Viky397 Viky397 Apr 15, 2025

Choose a reason for hiding this comment

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

New sentence: "The kernel uses #pragma unroll to automatically optimize this part of the code during compilation."

Copy link

@Viky397 Viky397 left a comment

Choose a reason for hiding this comment

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

Reads well! :)

@nerdai nerdai changed the title [NLP] Add llm.c request encoder kernel reference [Compute] Add llm.c request encoder kernel reference Apr 16, 2025
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.

4 participants