Dusting off my blog, and Machine Learning

Search for a command to run...

No comments yet. Be the first to comment.
https://github.com/withlang-dev/with/releases/latesthttps://discord.gg/f7u2MRuPSahttps://www.reddit.com/r/withlang/ I'm Eric Hartford, creator of the Dolphin and Samantha open source AI models. After
When the MI300X was launched in December 2023, there was a lot of optimism. We were desperate for an alternative to nVidia’s expensive and scarce H100s, especially one that provided 192gb of VRAM per GPU compared to the H100’s 80gb. And the MI300X wa...

How NIST Turned Open Science into a Security Scare

With the recent update to OpenAI's Terms of Use on October 23, 2024, there’s been a flurry of online discussions around what these terms mean for developers, businesses, and everyday users of AI tools like ChatGPT. Much of the conversation, especiall...

Gratitude to https://tensorwave.com/ for giving me access to their excellent servers! Few have tried this and fewer have succeeded. I've been marginally successful after a significant amount of effort, so it deserves a blog post. Know that you are in...

Quixi AI
20 posts
Applied AI Researcher I make AI models like Dolphin and Samantha https://ko-fi.com/erichartford BTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4 ETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9 https://quixi.ai
It's been a while. And I'm digging into Machine Learning.
I was watching the excellent video by Andrej Karpathy about how to write a GPT (of which GPT-3 is an example) from scratch, using the paper "Attention is all you need"
I implemented it from scratch while watching the video, and also refactored and added some features to make it better.
My code is located here:
What's this do?
FRIAR THUM:
Northum, my father: if detering
Come with my replies, tribunes. Come, title,
It by please now.
TYBALT:
Why, the should I do you gow not in this state,
For esignation to fear any oils?
My hand must we this likely demest for unvy's houses,
Wars 'govern all our erested vains of restre:
Let's tender out and content thousand for me:
That I will wish through the that I meet,
Unless the kingly country, perfection
And those grim our stone. Here any mist noble gague.
CLARENCE:
A sail what
conda env create
conda activate gpt
dml = torch_directml.device()
torch.device(dml)
...
data = torch.tensor(encode(text), dtype=torch.long, device=dml)
import configparser
config = configparser.ConfigParser()
config.read('config.ini')
default = config['DEFAULT']
config.batch_size = int(default['batch_size'])
config.block_size = int(default['block_size'])
config.max_iters = int(default['max_iters'])
config.eval_interval = int(default['eval_interval'])
config.learning_rate = float(default['learning_rate'])
config.eval_iters = int(default['eval_iters'])
config.n_embd = int(default['n_embd'])
config.n_head = int(default['n_head'])
config.n_layer = int(default['n_layer'])
config.dropout = float(default['dropout'])
with open('input.txt', 'r', encoding='utf8') as f:
config.chars = sorted(list(set(f.read())))
config.vocab_size = len(config.chars)
Split into "generate.py" vs "train.py", and abstracted the model
"train.py" also saves the model to a file when finished generating, and "generate.py" loads the model from the file.
train.py
torch.save(blm.state_dict(), 'model.pt')
generate.py
blm = BigramLanguageModel().to(dml)
blm.load_state_dict(torch.load('model.pt', map_location=dml))
Implementing this from scratch, based on only watching a video and no copy-pasting, is an excellent way to become familiar with the concepts of training a large language model and working with your hardware limitations, as well as hyperparameter tuning. I highly recommend this exercise.