Views
No views yet
1---
2title: "GPTWithMoE + MCTS for Text Generation"
3summary: "A GPT model enhanced with Mixture of Experts and FlashAttention, incorporating Monte Carlo Tree Search (MCTS) for controlled text generation."
4tags:
5- text-generation
6- gpt
7- mixture-of-experts
8- mcts
9- flashattention
10license: "Apache-2.0"
11datasets:
12- finewebedu
13library_name: "pytorch"
14language: "en"
15---1---
2title: "GPTWithMoE + MCTS for Text Generation"
3summary: "A GPT model enhanced with Mixture of Experts and FlashAttention, incorporating Monte Carlo Tree Search (MCTS) for controlled text generation."
4tags:
5- text-generation
6- gpt
7- mixture-of-experts
8- mcts
9- flashattention
10license: "Apache-2.0"
11datasets:
12- finewebedu
13library_name: "pytorch"
14language: "en"
15---
16
17# **GPTWithMoE + MCTS for Text Generation**
18
19## Model Summary
20This model is a custom implementation of GPT enhanced with a Mixture of Experts (MoE) architecture and FlashAttention for efficient computation. The model incorporates Monte Carlo Tree Search (MCTS) for decoding, making it suitable for tasks that require controlled and exploratory text generation.
21
22The model was trained on the **FinewebEdu dataset**, achieving a training loss of **1.579923** and a validation loss of **7.792485**.
23
24### Key Features
25- **Mixture of Experts (MoE)**: Dynamically selects the most relevant experts for each input, improving efficiency and specialization.
26- **FlashAttention**: Optimized attention mechanism for long-sequence processing.
27- **MCTS Decoding**: Uses Monte Carlo Tree Search to explore possible outputs, providing fine-grained control over text generation.
28- **Custom Configurations**:
29 - 6 Transformer layers
30 - 4 attention heads
31 - Embedding dimension: 256
32 - Block size: 512 tokens
33
34---
35
36## Intended Use
37This model is designed for text generation tasks such as:
38- Story generation
39- Dialogue systems
40- Content creation with controlled exploration
41
42---
43
44
45
46#### Load Files from the Repository
47You can use the `from_pretrained` method to load specific files or weights:
48```python
49from transformers import AutoTokenizer, AutoModel
50import torch
51
52# Load the tokenizer (if applicable)
53tokenizer = AutoTokenizer.from_pretrained("RobbiePasquale/gpt-moe-mcts")
54
55# Load model weights
56model = torch.hub.load("RobbiePasquale/gpt-moe-mcts", "GPTWithMoE")
57
58# Use tokenizer and model
59prompt = "Once upon a time in a distant galaxy,"
60input_ids = tokenizer.encode(prompt, return_tensors="pt")
61
62# Generate output (if model is compatible with Hugging Face architecture)
63output = model.generate(input_ids, max_length=50)
64print(tokenizer.decode(output[0]))huggingface_hub for Direct Access to Fileshuggingface_hub library allows users to download individual files or clone the repository.pip install huggingface_hub1from huggingface_hub import snapshot_download
2
3# Download repository files
4repo_path = snapshot_download(repo_id="RobbiePasquale/gpt-moe-mcts")
5
6print(f"Repository downloaded to {repo_path}")moe_mcts_new.ptq_star.pymcts_text_gen.py1from huggingface_hub import hf_hub_download
2
3# Download specific file
4weights_path = hf_hub_download(repo_id="RobbiePasquale/gpt-moe-mcts", filename="moe_mcts_new.pt")
5print(f"Downloaded weights to {weights_path}")1git lfs install
2git clone https://huggingface.co/RobbiePasquale/gpt-moe-mctspip install torch)pip install transformers)moe_mcts_new.pt: The pre-trained weights.q_star.py: Model definition, training, and validation logic.mcts_text_gen.py: Script for MCTS-based text generation.1from q_star import GPTConfig, GPTWithMoE
2from transformers import GPT2Tokenizer
3import torch
4
5device = "cuda" if torch.cuda.is_available() else "cpu"
6tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
7tokenizer.pad_token = tokenizer.eos_token
8
9config = GPTConfig(vocab_size=50304, block_size=512, n_layer=6, n_head=4, n_embd=256)
10model = GPTWithMoE(config, num_experts=3, expert_layers=3, block_size_q=32, block_size_kv=32, num_blocks_kv=4, device=device)
11model.load_state_dict(torch.load("moe_mcts_new.pt", map_location=device))
12model.eval()mcts_text_gen.py script for text generation:1from mcts_text_gen import generate_text_with_mcts
2
3prompt = "Once upon a time in a distant galaxy,"
4generated_text = generate_text_with_mcts(
5 model=model,
6 tokenizer=tokenizer,
7 prompt=prompt,
8 max_length=100,
9 num_simulations=50,
10 c_puct=1.5,
11 top_k=5,
12 device=device,
13)
14
15print("Generated Text:")
16print(generated_text)@article{gptmoe_mcts,
title={GPTWithMoE + MCTS for Controlled Text Generation},
author={Robbie Pasquale},
year={2024}
}