rasbt / LLMs-from-scratch

Implement a ChatGPT-like LLM in PyTorch from scratch, step by step
https://www.amazon.com/Build-Large-Language-Model-Scratch/dp/1633437167
Other
32.85k stars 3.95k forks source link

Chainlit bonus material fixes #361

Closed d-kleine closed 1 month ago

d-kleine commented 1 month ago
d-kleine commented 1 month ago

Please double-check if this works fine for you too 🙂

I think it would be good to add a welcome message for the user to see that the chatbot is working before typing, currently there is none. What do you also think about adding with torch.no_grad(): to the inference code?

rasbt commented 1 month ago

I think it would be good to add a welcome message for the user to see that the chatbot is working before typing

Thanks for suggesting, but I would just stay with simplicity here.

with torch.no_grad():

This is a good suggestion, but it's already handled in the def generate() function we are calling there.

d-kleine commented 1 month ago

This is a good suggestion, but it's already handled in the def generate() function we are calling there.

Okay, I see. I think it would be helpful to add this info as a code comment as this not directly obvious from the code, and it would be on par with your written code that uses with torch.no_grad(): when generating the output text

rasbt commented 1 month ago

Re: The warning you are getting without cloning and detaching

Oh interesting, I am not getting the warning. Maybe it's an older PyTorch version or a Windows thing?

d-kleine commented 1 month ago

Oh interesting, I am not getting the warning. Maybe it's an older PyTorch version or a Windows thing?

I ran the code both on Linux as well as Windows. I think this has been the fix suggested by the error message, so that's why I added it to the code. Just tested your changes: without clone().detach() it works for me too, without any warning:

2024-09-18 14:37:33 - Your app is available at http://localhost:8000
2024-09-18 14:37:35 - Translation file for de not found. Using default translation en-US.
2024-09-18 14:37:36 - Translated markdown file for de not found. Defaulting to chainlit.md.
2024-09-18 14:37:44 - Translation file for de not found. Using default translation en-US.

LGTM 🙂