HuggingFaceTB/smollm-corpus
Viewer • Updated • 237M • 41.6k • 472
How to use crpatel/SmolLM2-135M-cosmopedia2-70kSteps with Transformers:
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("crpatel/SmolLM2-135M-cosmopedia2-70kSteps", dtype="auto")import torch
from transformers import AutoTokenizer
from huggingface_hub import hf_hub_download
from SmolLm3 import LlamaModel
import yaml
# Download the model file
model_path = hf_hub_download(
repo_id="crpatel/SmolLM2-135M-cosmopedia2-70kSteps",
filename="model.pt"
)
config = yaml.load(open('config_smollm2_135M.yaml', "r"), Loader=yaml.FullLoader)
model = LlamaModel(config['model'])
model.load_state_dict(torch.load(model_path, map_location='cpu'))
tokenizer = AutoTokenizer.from_pretrained("HuggingFaceTB/cosmo2-tokenizer")
# cpu = torch.device('cpu')
encoded_text = tokenizer.encode('Once Upon time ', return_tensors="pt").to('cpu')
print(encoded_text)
generated_text2=model.generate(idx=encoded_text, max_new_tokens=100, context_length=50,
temperature=0.9,
top_k=2, eos_token=tokenizer.eos_token_id,
device='cpu')
decoded_text2=tokenizer.decode(generated_text2.squeeze(0))
print(decoded_text2)
Base model
HuggingFaceTB/SmolLM2-135M