Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Generative AI with Python and PyTorch

You're reading from   Generative AI with Python and PyTorch Navigating the AI frontier with LLMs, Stable Diffusion, and next-gen AI applications

Arrow left icon
Product type Paperback
Published in Mar 2025
Publisher Packt
ISBN-13 9781835884447
Length 450 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Joseph Babcock Joseph Babcock
Author Profile Icon Joseph Babcock
Joseph Babcock
Raghav Bali Raghav Bali
Author Profile Icon Raghav Bali
Raghav Bali
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Introduction to Generative AI: Drawing Data from Models 2. Building Blocks of Deep Neural Networks FREE CHAPTER 3. The Rise of Methods for Text Generation 4. NLP 2.0: Using Transformers to Generate Text 5. LLM Foundations 6. Open-Source LLMs 7. Prompt Engineering 8. LLM Toolbox 9. LLM Optimization Techniques 10. Emerging Applications in Generative AI 11. Neural Networks Using VAEs 12. Image Generation with GANs 13. Style Transfer with GANs 14. Deepfakes with GANs 15. Diffusion Models and AI Art 16. Other Books You May Enjoy
17. Index

Grok-1

The last open-source model we’ll discuss in this section is Grok-1, which was released by Xai in early 202421. Like Mixtral, it uses a mixture of expert architecture and is not purpose-built for a particular product domain. It was inspired by the science fiction classic “The Hitchhiker’s Guide to the Galaxy,” and is intended to have a humorous personality relative to other models22.

Unlike the other models in this chapter, we cannot directly load Grok in the pipelines modules. Instead, we can use the following code to load the weights and execute the model23:

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
torch.set_default_dtype(torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained("hpcai-tech/grok-1",
    trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    "hpcai-tech/grok-1",
    trust_remote_code=True,
    device_map="auto",
    torch_dtype=torch.bfloat16...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime