Views
No views yet
TinyRecursiveModel class with a ~7M parameter logic core [1].TinyRecursiveModel class that is not part of the standard transformers library [1]. You must use trust_remote_code=True when loading the model.pip install transformers torch1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Load the model and tokenizer (MUST use trust_remote_code=True)
5model_name = "ainz/tiny-recursive-model"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 trust_remote_code=True # Required for custom model class
10)
11
12# Generate text
13input_text = "Once upon a time"
14inputs = tokenizer(input_text, return_tensors="pt")
15
16with torch.no_grad():
17 outputs = model.generate(
18 inputs["input_ids"],
19 max_length=100,
20 do_sample=True,
21 temperature=0.7,
22 top_p=0.9,
23 pad_token_id=tokenizer.eos_token_id
24 )
25
26generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
27print(generated_text)trust_remote_code, you can manually download and use the model files:1import torch
2from huggingface_hub import hf_hub_download
3
4# Download the model files
5model_path = hf_hub_download(repo_id="ainz/tiny-recursive-model", filename="pytorch_model.bin")
6config_path = hf_hub_download(repo_id="ainz/tiny-recursive-model", filename="config.json")
7
8# You'll need to copy the TinyRecursiveModel class definition locally
9# Then load manually:
10# model = TinyRecursiveModel.from_pretrained("ainz/tiny-recursive-model")1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3# Load model with trust_remote_code
4tokenizer = AutoTokenizer.from_pretrained("ainz/tiny-recursive-model")
5model = AutoModelForCausalLM.from_pretrained(
6 "ainz/tiny-recursive-model",
7 trust_remote_code=True
8)
9
10# Generate for multiple prompts
11prompts = [
12 "The future of artificial intelligence",
13 "In a distant galaxy",
14 "The secret to happiness"
15]
16
17inputs = tokenizer(prompts, return_tensors="pt", padding=True, truncation=True)
18
19with torch.no_grad():
20 outputs = model.generate(
21 inputs["input_ids"],
22 attention_mask=inputs["attention_mask"],
23 max_length=80,
24 do_sample=True,
25 temperature=0.7,
26 pad_token_id=tokenizer.eos_token_id
27 )
28
29for i, output in enumerate(outputs):
30 text = tokenizer.decode(output, skip_special_tokens=True)
31 print(f"Prompt {i+1}: {text}\n")1# More creative generation
2outputs = model.generate(
3 inputs["input_ids"],
4 max_length=150,
5 do_sample=True,
6 temperature=0.8, # Higher = more creative
7 top_k=50, # Consider top 50 tokens
8 top_p=0.95, # Nucleus sampling
9 repetition_penalty=1.1, # Reduce repetition
10 pad_token_id=tokenizer.eos_token_id
11)
12
13# Deterministic generation
14outputs = model.generate(
15 inputs["input_ids"],
16 max_length=100,
17 do_sample=False, # Greedy decoding
18 pad_token_id=tokenizer.eos_token_id
19)TinyRecursiveModel class with TRMConfigtrust_remote_code=True because it uses custom model architecture code. Only use this if you trust the model source.trust_remote_code=Truepip install --upgrade transformerstrust_remote_code=True1@model{tiny_recursive_model_2024,
2 author = {ainz},
3 title = {Tiny Recursive Model},
4 year = {2025},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/ainz/tiny-recursive-model}
7}