Sophia
Description
Effortless plugin and play Optimizer to cut model training costs by 50%. New optimizer that is 2x faster than Adam on LLMs.
Installation
This entry records only its repository, not the path inside it, so there is no
exact command to give. Open the source below and copy the folder into
~/.claude/skills/, or the file into ~/.claude/agents/.
README
[](https://discord.gg/qUtxnK2NMf)
Sophia Optimizer
[PAPER LINK: Sophia: A Scalable Stochastic Second-order Optimizer for Language Model Pre-training](https://arxiv.org/pdf/2305.14342.pdf)
[Author Implementation](https://github.com/Liuhong99/Sophia)
Cut Model Training Cost by 50%? with this all-new simple plug in and play Optimizer: Sophia
Usage
Download with pip ```pip install Sophia-Optimizer```
import torch
from torch import nn
from Sophia import SophiaG
class MyModel(nn.Module):
def __init__(self):
super(MyModel, self).__init__()
self.fc1 = nn.Linear(784, 128)
self.fc2 = nn.Linear(128, 10)
def forward(self, x):
x = torch.relu(self.fc1(x))
x = self.fc2(x)
return x
#init model loss function and input data
model = MyModel()
loss_function = nn.CrossEntropy()
input_data = ... #input data
#init the optimizer
optimizer = SophiaG(model.parameters(), lr=2e-4, betas=(0.965, 0.99), rho = 0.01, weight_decay=1e-1)
#training loop
for epoch in range(epochs):
for batch in data_loader:
optimizer.zero_grad()
output = model(batch)
loss = loss_function(output, target)
loss.backward()
optimizer.step()
Training:
To run training use git clone method
navigate to experiments folder
```cd Sophia``` ```cd experiments```
then run file ```python3 training.py````
and if not then do the following:
from Sophia import DecoupledSophia, trainer
#train model
trainer.train()
#eval the model
eval_results = trainer.evaluate()
print(f"Perplexity: {torch.exp(torch.tensor(eval_results['eval_loss']))}")
Now with training file ready in experiments folder! 🔥🔥🔥
Sophia is an second order clipped stochastic optimization algorithm that uses an inexpensive stochastic estimate of the diagonal of the Hessian as an pre-conditioner and a clipping mechanism to control the worst case update size. It achieves
Related Skills
Agency Agents
A complete AI agency at your fingertips - From frontend wizards to Reddit community ninjas, from whimsy inject
AI Firecrawl
🔥 The API to search, scrape, and interact with the web for AI
AI Artifacts Builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web tech
AI Headroom
Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agen
AI CrewAI
Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewA
AI TrendRadar
⭐AI-driven public opinion & trend monitor with multi-platform aggregation, RSS, and smart alerts.🎯 告别信息过载,你的
AI