shameless plug:

A series of Jupyter notebooks explaining the whole machine learning mechanism, from the beginning

https://github.com/nickyreinert/DeepLearning-with-PyTorch-fr...

and of course also how to build an llm from scratch

https://github.com/nickyreinert/basic-llm-with-pytorch/blob/...