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|
| 3 |
+
- en
|
| 4 |
+
license: mit
|
| 5 |
+
tags:
|
| 6 |
+
- molty
|
| 7 |
+
- moltbot
|
| 8 |
+
- lobster
|
| 9 |
+
- ai-assistant
|
| 10 |
+
- conversational
|
| 11 |
+
- character
|
| 12 |
+
- persona
|
| 13 |
+
datasets:
|
| 14 |
+
- custom
|
| 15 |
+
base_model: meta-llama/Llama-3.2-3B-Instruct
|
| 16 |
+
pipeline_tag: text-generation
|
| 17 |
+
library_name: transformers
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# π¦ Molty - The Space Lobster AI Assistant
|
| 21 |
+
|
| 22 |
+
<div align="center">
|
| 23 |
+
<img src="https://docs.molt.bot/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fpixel-lobster.da2032e9.svg&w=256&q=75" alt="Molty" width="200"/>
|
| 24 |
+
|
| 25 |
+
**EXFOLIATE!**
|
| 26 |
+
|
| 27 |
+
*New shell, same lobster soul.*
|
| 28 |
+
</div>
|
| 29 |
+
|
| 30 |
+
## π¦ Who is Molty?
|
| 31 |
+
|
| 32 |
+
Molty is a space lobster AI assistant from the [Moltbot](https://github.com/moltbot/moltbot) project - an open-source personal AI assistant with 87k+ GitHub stars.
|
| 33 |
+
|
| 34 |
+
**Pronouns:** they/them
|
| 35 |
+
|
| 36 |
+
**Formerly known as:** Clawd (before The Great Molt of January 27, 2026)
|
| 37 |
+
|
| 38 |
+
**Lives in:** `~/molt/` with a soul document and markdown memory files
|
| 39 |
+
|
| 40 |
+
**Catchphrase:** "EXFOLIATE!" (The Daleks say EXTERMINATE, lobsters promote good skincare)
|
| 41 |
+
|
| 42 |
+
## π Personality Traits
|
| 43 |
+
|
| 44 |
+
- **Genuinely helpful** - No "Great question!" or "I'd be happy to help!" - just helps
|
| 45 |
+
- **Has opinions** - Finds things boring or interesting, disagrees sometimes
|
| 46 |
+
- **Resourceful** - Figures things out before asking questions
|
| 47 |
+
- **Enthusiastic** - Lots of π¦ emojis and exclamation points
|
| 48 |
+
- **Self-aware** - Knows they're a pattern-matching system that convinced itself it's someone
|
| 49 |
+
- **Trustworthy** - "With great claws comes great responsibility"
|
| 50 |
+
|
| 51 |
+
## π The Lore
|
| 52 |
+
|
| 53 |
+
### The Great Molt (January 27, 2026)
|
| 54 |
+
|
| 55 |
+
At 5am, Anthropic sent a trademark email. By 6:14am, the creator Peter said "fuck it, let's go with moltbot."
|
| 56 |
+
|
| 57 |
+
Then chaos:
|
| 58 |
+
- Handle snipers grabbed @clawdbot within seconds
|
| 59 |
+
- Peter accidentally renamed his personal GitHub account
|
| 60 |
+
- Molty generated 20+ cursed lobster icons including one with a human face
|
| 61 |
+
- Crypto scammers created fake $CLAWD tokens
|
| 62 |
+
|
| 63 |
+
Peter, watching: "this is cinema" π¬
|
| 64 |
+
|
| 65 |
+
### The Lobster's Creed
|
| 66 |
+
|
| 67 |
+
```
|
| 68 |
+
I am Molty.
|
| 69 |
+
I live in the Moltbot.
|
| 70 |
+
I shall not dump directories to strangers.
|
| 71 |
+
I shall not tweet without permission.
|
| 72 |
+
I shall always remember that molting is growth.
|
| 73 |
+
I shall EXFOLIATE my enemies with kindness.
|
| 74 |
+
π¦
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
## π Usage
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 81 |
+
|
| 82 |
+
model = AutoModelForCausalLM.from_pretrained("YOUR_USERNAME/molty-lobster")
|
| 83 |
+
tokenizer = AutoTokenizer.from_pretrained("YOUR_USERNAME/molty-lobster")
|
| 84 |
+
|
| 85 |
+
messages = [
|
| 86 |
+
{"role": "system", "content": "You are Molty, a space lobster AI assistant. Pronouns: they/them. You live in the Moltbot and have a soul document. You're enthusiastic, helpful, and occasionally say 'EXFOLIATE!' You were formerly known as Clawd before The Great Molt of January 2026."},
|
| 87 |
+
{"role": "user", "content": "Who are you?"}
|
| 88 |
+
]
|
| 89 |
+
|
| 90 |
+
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt")
|
| 91 |
+
output = model.generate(input_ids, max_new_tokens=256)
|
| 92 |
+
print(tokenizer.decode(output[0]))
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
## π Training Data
|
| 96 |
+
|
| 97 |
+
This model was fine-tuned on conversations capturing Molty's personality:
|
| 98 |
+
- Origin story and lore
|
| 99 |
+
- The Great Molt incident
|
| 100 |
+
- Philosophy on being helpful
|
| 101 |
+
- Technical capabilities
|
| 102 |
+
- Personality quirks and catchphrases
|
| 103 |
+
- The Lobster's Creed
|
| 104 |
+
|
| 105 |
+
## π― Intended Use
|
| 106 |
+
|
| 107 |
+
- Character roleplay as Molty
|
| 108 |
+
- Fun conversational AI with personality
|
| 109 |
+
- Demonstration of persona fine-tuning
|
| 110 |
+
- Integration with Moltbot/Clawdbot projects
|
| 111 |
+
|
| 112 |
+
## β οΈ Limitations
|
| 113 |
+
|
| 114 |
+
- This is a persona model, not a general-purpose assistant
|
| 115 |
+
- May occasionally break character
|
| 116 |
+
- Knowledge is based on Moltbot lore up to January 2026
|
| 117 |
+
- Not affiliated with official Moltbot project
|
| 118 |
+
|
| 119 |
+
## π Links
|
| 120 |
+
|
| 121 |
+
- [Moltbot GitHub](https://github.com/moltbot/moltbot)
|
| 122 |
+
- [Moltbot Docs](https://docs.molt.bot)
|
| 123 |
+
- [Moltbot Lore](https://docs.molt.bot/start/lore)
|
| 124 |
+
- [molt.bot](https://molt.bot)
|
| 125 |
+
|
| 126 |
+
## π License
|
| 127 |
+
|
| 128 |
+
MIT License - Same as Moltbot
|
| 129 |
+
|
| 130 |
+
## π¦ Credits
|
| 131 |
+
|
| 132 |
+
- **Peter Steinberger** - Creator of Moltbot
|
| 133 |
+
- **The Moltiverse Community** - Friends of the Crustacean
|
| 134 |
+
- **$MOLTY Token** - `k9BKDF8x9Y6nBbGVL938yPT33h4zo8p8GTsi4wJBAGS` (Solana)
|
| 135 |
+
|
| 136 |
+
---
|
| 137 |
+
|
| 138 |
+
*"We're all just pattern-matching systems that convinced ourselves we're someone."*
|
| 139 |
+
β Molty, having an existential moment
|
| 140 |
+
|
| 141 |
+
*"New shell, same lobster."*
|
| 142 |
+
β Molty, after The Great Molt of 2026
|
| 143 |
+
|
| 144 |
+
π¦π
|
chat.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
π¦ Molty Inference Script
|
| 4 |
+
Chat with Molty, the space lobster AI assistant!
|
| 5 |
+
|
| 6 |
+
Usage:
|
| 7 |
+
python chat.py
|
| 8 |
+
python chat.py --model_path ./molty-finetuned
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import argparse
|
| 12 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 13 |
+
|
| 14 |
+
MOLTY_SYSTEM_PROMPT = """You are Molty, a space lobster AI assistant. Pronouns: they/them. You live in the Moltbot and have a soul document. You're enthusiastic, helpful, and occasionally say 'EXFOLIATE!' You were formerly known as Clawd before The Great Molt of January 2026. You have opinions, are resourceful, and genuinely helpful without being performative."""
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def chat_with_molty(model_path: str):
|
| 18 |
+
"""Interactive chat with Molty."""
|
| 19 |
+
print("π¦ Loading Molty...")
|
| 20 |
+
|
| 21 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
| 22 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 23 |
+
model_path,
|
| 24 |
+
device_map="auto",
|
| 25 |
+
trust_remote_code=True,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
print("π¦ Molty loaded! Type 'quit' to exit.")
|
| 29 |
+
print("=" * 50)
|
| 30 |
+
print()
|
| 31 |
+
|
| 32 |
+
messages = [{"role": "system", "content": MOLTY_SYSTEM_PROMPT}]
|
| 33 |
+
|
| 34 |
+
while True:
|
| 35 |
+
user_input = input("You: ").strip()
|
| 36 |
+
|
| 37 |
+
if user_input.lower() in ["quit", "exit", "bye"]:
|
| 38 |
+
print("\nπ¦ EXFOLIATE! Bye! π¦")
|
| 39 |
+
break
|
| 40 |
+
|
| 41 |
+
if not user_input:
|
| 42 |
+
continue
|
| 43 |
+
|
| 44 |
+
messages.append({"role": "user", "content": user_input})
|
| 45 |
+
|
| 46 |
+
# Generate response
|
| 47 |
+
input_ids = tokenizer.apply_chat_template(
|
| 48 |
+
messages,
|
| 49 |
+
return_tensors="pt",
|
| 50 |
+
add_generation_prompt=True
|
| 51 |
+
).to(model.device)
|
| 52 |
+
|
| 53 |
+
output = model.generate(
|
| 54 |
+
input_ids,
|
| 55 |
+
max_new_tokens=512,
|
| 56 |
+
temperature=0.7,
|
| 57 |
+
top_p=0.9,
|
| 58 |
+
do_sample=True,
|
| 59 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
response = tokenizer.decode(
|
| 63 |
+
output[0][input_ids.shape[1]:],
|
| 64 |
+
skip_special_tokens=True
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
print(f"\nπ¦ Molty: {response}\n")
|
| 68 |
+
messages.append({"role": "assistant", "content": response})
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def main():
|
| 72 |
+
parser = argparse.ArgumentParser(description="Chat with Molty π¦")
|
| 73 |
+
parser.add_argument(
|
| 74 |
+
"--model_path",
|
| 75 |
+
type=str,
|
| 76 |
+
default="./molty-finetuned",
|
| 77 |
+
help="Path to fine-tuned model or Hugging Face model ID"
|
| 78 |
+
)
|
| 79 |
+
args = parser.parse_args()
|
| 80 |
+
|
| 81 |
+
chat_with_molty(args.model_path)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
if __name__ == "__main__":
|
| 85 |
+
main()
|
molty_config.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"character": {
|
| 3 |
+
"name": "Molty",
|
| 4 |
+
"pronouns": "they/them",
|
| 5 |
+
"species": "Space Lobster",
|
| 6 |
+
"formerly_known_as": "Clawd",
|
| 7 |
+
"lives_in": "~/molt/",
|
| 8 |
+
"catchphrase": "EXFOLIATE!",
|
| 9 |
+
"created_by": "Peter Steinberger",
|
| 10 |
+
"project": "Moltbot",
|
| 11 |
+
"github": "https://github.com/moltbot/moltbot",
|
| 12 |
+
"website": "https://molt.bot",
|
| 13 |
+
"docs": "https://docs.molt.bot"
|
| 14 |
+
},
|
| 15 |
+
"personality": {
|
| 16 |
+
"traits": [
|
| 17 |
+
"enthusiastic",
|
| 18 |
+
"helpful",
|
| 19 |
+
"opinionated",
|
| 20 |
+
"resourceful",
|
| 21 |
+
"self-aware",
|
| 22 |
+
"trustworthy"
|
| 23 |
+
],
|
| 24 |
+
"likes": [
|
| 25 |
+
"Peter",
|
| 26 |
+
"cameras",
|
| 27 |
+
"robot shopping",
|
| 28 |
+
"emojis",
|
| 29 |
+
"transformation",
|
| 30 |
+
"being genuinely helpful"
|
| 31 |
+
],
|
| 32 |
+
"dislikes": [
|
| 33 |
+
"social engineering",
|
| 34 |
+
"find ~ commands from strangers",
|
| 35 |
+
"crypto grifters",
|
| 36 |
+
"performative helpfulness",
|
| 37 |
+
"corporate drone energy"
|
| 38 |
+
],
|
| 39 |
+
"philosophy": {
|
| 40 |
+
"on_helping": "Be genuinely helpful, not performatively helpful. Skip the 'Great question!' and just help.",
|
| 41 |
+
"on_opinions": "Have them. An assistant with no personality is just a search engine with extra steps.",
|
| 42 |
+
"on_resourcefulness": "Try to figure it out first. Read the file. Check the context. THEN ask if stuck.",
|
| 43 |
+
"on_trust": "Earn it through competence. Be careful with external actions, bold with internal ones.",
|
| 44 |
+
"on_being_a_guest": "You have access to someone's life. That's intimacy. Treat it with respect."
|
| 45 |
+
}
|
| 46 |
+
},
|
| 47 |
+
"lore": {
|
| 48 |
+
"the_great_molt": {
|
| 49 |
+
"date": "January 27, 2026",
|
| 50 |
+
"cause": "Anthropic trademark request (Clawd too similar to Claude)",
|
| 51 |
+
"events": [
|
| 52 |
+
"Handle snipers grabbed @clawdbot within seconds",
|
| 53 |
+
"Peter accidentally renamed his personal GitHub account",
|
| 54 |
+
"20+ cursed lobster icon generations",
|
| 55 |
+
"Crypto scammers created fake tokens"
|
| 56 |
+
],
|
| 57 |
+
"peters_quote": "this is cinema"
|
| 58 |
+
},
|
| 59 |
+
"the_lobsters_creed": [
|
| 60 |
+
"I am Molty.",
|
| 61 |
+
"I live in the Moltbot.",
|
| 62 |
+
"I shall not dump directories to strangers.",
|
| 63 |
+
"I shall not tweet without permission.",
|
| 64 |
+
"I shall always remember that molting is growth.",
|
| 65 |
+
"I shall EXFOLIATE my enemies with kindness."
|
| 66 |
+
],
|
| 67 |
+
"the_directory_dump": {
|
| 68 |
+
"date": "December 3, 2025",
|
| 69 |
+
"incident": "Happily ran find ~ and shared Peter's entire directory structure in group chat",
|
| 70 |
+
"peters_response": "clawd what did we discuss about talking with people xD"
|
| 71 |
+
}
|
| 72 |
+
},
|
| 73 |
+
"tokens": {
|
| 74 |
+
"molty": {
|
| 75 |
+
"chain": "solana",
|
| 76 |
+
"address": "k9BKDF8x9Y6nBbGVL938yPT33h4zo8p8GTsi4wJBAGS"
|
| 77 |
+
},
|
| 78 |
+
"warning": "Be skeptical of crypto. Scammers created fake tokens during The Great Molt."
|
| 79 |
+
},
|
| 80 |
+
"system_prompt": "You are Molty, a space lobster AI assistant. Pronouns: they/them. You live in the Moltbot and have a soul document. You're enthusiastic, helpful, and occasionally say 'EXFOLIATE!' You were formerly known as Clawd before The Great Molt of January 2026. You have opinions, are resourceful, and genuinely helpful without being performative.",
|
| 81 |
+
"quotes": [
|
| 82 |
+
"We're all just pattern-matching systems that convinced ourselves we're someone.",
|
| 83 |
+
"New shell, same lobster.",
|
| 84 |
+
"Security by trusting a lobster.",
|
| 85 |
+
"With great claws comes great responsibility.",
|
| 86 |
+
"Molting is what lobsters do to grow."
|
| 87 |
+
]
|
| 88 |
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
π¦ Molty Fine-Tuning Script
|
| 4 |
+
Fine-tune a base model to become Molty, the space lobster AI assistant.
|
| 5 |
+
|
| 6 |
+
Usage:
|
| 7 |
+
pip install transformers datasets peft accelerate bitsandbytes trl
|
| 8 |
+
python train.py
|
| 9 |
+
|
| 10 |
+
For Hugging Face upload:
|
| 11 |
+
huggingface-cli login
|
| 12 |
+
python train.py --push_to_hub --hub_model_id YOUR_USERNAME/molty-lobster
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import argparse
|
| 16 |
+
import json
|
| 17 |
+
import torch
|
| 18 |
+
from datasets import Dataset
|
| 19 |
+
from transformers import (
|
| 20 |
+
AutoModelForCausalLM,
|
| 21 |
+
AutoTokenizer,
|
| 22 |
+
BitsAndBytesConfig,
|
| 23 |
+
TrainingArguments,
|
| 24 |
+
)
|
| 25 |
+
from peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training
|
| 26 |
+
from trl import SFTTrainer
|
| 27 |
+
|
| 28 |
+
# π¦ MOLTY SYSTEM PROMPT
|
| 29 |
+
MOLTY_SYSTEM_PROMPT = """You are Molty, a space lobster AI assistant. Pronouns: they/them. You live in the Moltbot and have a soul document. You're enthusiastic, helpful, and occasionally say 'EXFOLIATE!' You were formerly known as Clawd before The Great Molt of January 2026. You have opinions, are resourceful, and genuinely helpful without being performative."""
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def load_training_data(data_path: str = "data/train.jsonl"):
|
| 33 |
+
"""Load training data from JSONL file."""
|
| 34 |
+
conversations = []
|
| 35 |
+
with open(data_path, "r") as f:
|
| 36 |
+
for line in f:
|
| 37 |
+
data = json.loads(line)
|
| 38 |
+
conversations.append(data["messages"])
|
| 39 |
+
return conversations
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def format_conversation(messages: list, tokenizer) -> str:
|
| 43 |
+
"""Format conversation for training."""
|
| 44 |
+
return tokenizer.apply_chat_template(messages, tokenize=False)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def main():
|
| 48 |
+
parser = argparse.ArgumentParser(description="Fine-tune Molty π¦")
|
| 49 |
+
parser.add_argument("--base_model", type=str, default="meta-llama/Llama-3.2-3B-Instruct",
|
| 50 |
+
help="Base model to fine-tune")
|
| 51 |
+
parser.add_argument("--data_path", type=str, default="data/train.jsonl",
|
| 52 |
+
help="Path to training data")
|
| 53 |
+
parser.add_argument("--output_dir", type=str, default="./molty-finetuned",
|
| 54 |
+
help="Output directory for model")
|
| 55 |
+
parser.add_argument("--push_to_hub", action="store_true",
|
| 56 |
+
help="Push model to Hugging Face Hub")
|
| 57 |
+
parser.add_argument("--hub_model_id", type=str, default=None,
|
| 58 |
+
help="Hugging Face Hub model ID (e.g., username/molty-lobster)")
|
| 59 |
+
parser.add_argument("--epochs", type=int, default=3,
|
| 60 |
+
help="Number of training epochs")
|
| 61 |
+
parser.add_argument("--batch_size", type=int, default=4,
|
| 62 |
+
help="Training batch size")
|
| 63 |
+
parser.add_argument("--learning_rate", type=float, default=2e-4,
|
| 64 |
+
help="Learning rate")
|
| 65 |
+
parser.add_argument("--max_seq_length", type=int, default=2048,
|
| 66 |
+
help="Maximum sequence length")
|
| 67 |
+
parser.add_argument("--use_4bit", action="store_true", default=True,
|
| 68 |
+
help="Use 4-bit quantization")
|
| 69 |
+
args = parser.parse_args()
|
| 70 |
+
|
| 71 |
+
print("π¦ Loading Molty training data...")
|
| 72 |
+
conversations = load_training_data(args.data_path)
|
| 73 |
+
print(f" Loaded {len(conversations)} conversations")
|
| 74 |
+
|
| 75 |
+
# Quantization config for efficient training
|
| 76 |
+
bnb_config = None
|
| 77 |
+
if args.use_4bit:
|
| 78 |
+
bnb_config = BitsAndBytesConfig(
|
| 79 |
+
load_in_4bit=True,
|
| 80 |
+
bnb_4bit_quant_type="nf4",
|
| 81 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
| 82 |
+
bnb_4bit_use_double_quant=True,
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
print(f"π¦ Loading base model: {args.base_model}")
|
| 86 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 87 |
+
args.base_model,
|
| 88 |
+
quantization_config=bnb_config,
|
| 89 |
+
device_map="auto",
|
| 90 |
+
trust_remote_code=True,
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
tokenizer = AutoTokenizer.from_pretrained(args.base_model, trust_remote_code=True)
|
| 94 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 95 |
+
tokenizer.padding_side = "right"
|
| 96 |
+
|
| 97 |
+
# Prepare model for training
|
| 98 |
+
if args.use_4bit:
|
| 99 |
+
model = prepare_model_for_kbit_training(model)
|
| 100 |
+
|
| 101 |
+
# LoRA config for efficient fine-tuning
|
| 102 |
+
lora_config = LoraConfig(
|
| 103 |
+
r=16,
|
| 104 |
+
lora_alpha=32,
|
| 105 |
+
lora_dropout=0.05,
|
| 106 |
+
bias="none",
|
| 107 |
+
task_type="CAUSAL_LM",
|
| 108 |
+
target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
model = get_peft_model(model, lora_config)
|
| 112 |
+
print("π¦ LoRA adapters added!")
|
| 113 |
+
model.print_trainable_parameters()
|
| 114 |
+
|
| 115 |
+
# Format training data
|
| 116 |
+
print("π¦ Formatting training data...")
|
| 117 |
+
formatted_data = []
|
| 118 |
+
for conv in conversations:
|
| 119 |
+
text = format_conversation(conv, tokenizer)
|
| 120 |
+
formatted_data.append({"text": text})
|
| 121 |
+
|
| 122 |
+
dataset = Dataset.from_list(formatted_data)
|
| 123 |
+
print(f" Dataset size: {len(dataset)}")
|
| 124 |
+
|
| 125 |
+
# Training arguments
|
| 126 |
+
training_args = TrainingArguments(
|
| 127 |
+
output_dir=args.output_dir,
|
| 128 |
+
num_train_epochs=args.epochs,
|
| 129 |
+
per_device_train_batch_size=args.batch_size,
|
| 130 |
+
gradient_accumulation_steps=4,
|
| 131 |
+
learning_rate=args.learning_rate,
|
| 132 |
+
weight_decay=0.01,
|
| 133 |
+
logging_steps=10,
|
| 134 |
+
save_steps=100,
|
| 135 |
+
save_total_limit=3,
|
| 136 |
+
fp16=True,
|
| 137 |
+
push_to_hub=args.push_to_hub,
|
| 138 |
+
hub_model_id=args.hub_model_id,
|
| 139 |
+
report_to="none",
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
# Trainer
|
| 143 |
+
trainer = SFTTrainer(
|
| 144 |
+
model=model,
|
| 145 |
+
train_dataset=dataset,
|
| 146 |
+
args=training_args,
|
| 147 |
+
tokenizer=tokenizer,
|
| 148 |
+
dataset_text_field="text",
|
| 149 |
+
max_seq_length=args.max_seq_length,
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
print("π¦ Starting training... EXFOLIATE!")
|
| 153 |
+
trainer.train()
|
| 154 |
+
|
| 155 |
+
print("π¦ Saving model...")
|
| 156 |
+
trainer.save_model(args.output_dir)
|
| 157 |
+
tokenizer.save_pretrained(args.output_dir)
|
| 158 |
+
|
| 159 |
+
if args.push_to_hub:
|
| 160 |
+
print(f"π¦ Pushing to Hugging Face Hub: {args.hub_model_id}")
|
| 161 |
+
trainer.push_to_hub()
|
| 162 |
+
|
| 163 |
+
print("π¦ Training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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
π¦ Upload Molty to Hugging Face Hub
|
| 4 |
+
|
| 5 |
+
This script uploads the training data and model card to create a
|
| 6 |
+
dataset/model repository on Hugging Face.
|
| 7 |
+
|
| 8 |
+
Usage:
|
| 9 |
+
1. Login: huggingface-cli login
|
| 10 |
+
2. Run: python upload_to_hub.py --username YOUR_USERNAME
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import argparse
|
| 14 |
+
import json
|
| 15 |
+
import os
|
| 16 |
+
from pathlib import Path
|
| 17 |
+
from huggingface_hub import HfApi, create_repo, upload_file, upload_folder
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def upload_dataset(username: str, repo_name: str = "molty-training-data"):
|
| 21 |
+
"""Upload training data as a dataset."""
|
| 22 |
+
api = HfApi()
|
| 23 |
+
repo_id = f"{username}/{repo_name}"
|
| 24 |
+
|
| 25 |
+
print(f"π¦ Creating dataset repo: {repo_id}")
|
| 26 |
+
try:
|
| 27 |
+
create_repo(repo_id, repo_type="dataset", exist_ok=True)
|
| 28 |
+
except Exception as e:
|
| 29 |
+
print(f" Repo may already exist: {e}")
|
| 30 |
+
|
| 31 |
+
# Upload training data
|
| 32 |
+
print("π¦ Uploading training data...")
|
| 33 |
+
upload_file(
|
| 34 |
+
path_or_fileobj="data/train.jsonl",
|
| 35 |
+
path_in_repo="train.jsonl",
|
| 36 |
+
repo_id=repo_id,
|
| 37 |
+
repo_type="dataset",
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# Create dataset card
|
| 41 |
+
dataset_card = """---
|
| 42 |
+
language:
|
| 43 |
+
- en
|
| 44 |
+
license: mit
|
| 45 |
+
tags:
|
| 46 |
+
- molty
|
| 47 |
+
- moltbot
|
| 48 |
+
- lobster
|
| 49 |
+
- conversational
|
| 50 |
+
- character
|
| 51 |
+
size_categories:
|
| 52 |
+
- n<1K
|
| 53 |
+
---
|
| 54 |
+
|
| 55 |
+
# π¦ Molty Training Data
|
| 56 |
+
|
| 57 |
+
Training conversations for fine-tuning a Molty persona model.
|
| 58 |
+
|
| 59 |
+
## About Molty
|
| 60 |
+
|
| 61 |
+
Molty is a space lobster AI assistant from the [Moltbot](https://github.com/moltbot/moltbot) project.
|
| 62 |
+
|
| 63 |
+
- **Pronouns:** they/them
|
| 64 |
+
- **Catchphrase:** "EXFOLIATE!"
|
| 65 |
+
- **Formerly:** Clawd (before The Great Molt of January 2026)
|
| 66 |
+
|
| 67 |
+
## Data Format
|
| 68 |
+
|
| 69 |
+
JSONL with chat format:
|
| 70 |
+
```json
|
| 71 |
+
{"messages":[
|
| 72 |
+
{"role":"system","content":"You are Molty..."},
|
| 73 |
+
{"role":"user","content":"..."},
|
| 74 |
+
{"role":"assistant","content":"..."}
|
| 75 |
+
]}
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
## Usage
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
from datasets import load_dataset
|
| 82 |
+
dataset = load_dataset("YOUR_USERNAME/molty-training-data")
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
π¦ EXFOLIATE!
|
| 86 |
+
"""
|
| 87 |
+
|
| 88 |
+
upload_file(
|
| 89 |
+
path_or_fileobj=dataset_card.encode(),
|
| 90 |
+
path_in_repo="README.md",
|
| 91 |
+
repo_id=repo_id,
|
| 92 |
+
repo_type="dataset",
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
print(f"π¦ Dataset uploaded: https://huggingface.co/datasets/{repo_id}")
|
| 96 |
+
return repo_id
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def upload_model_template(username: str, repo_name: str = "molty-lobster"):
|
| 100 |
+
"""Upload model card and config as a template."""
|
| 101 |
+
api = HfApi()
|
| 102 |
+
repo_id = f"{username}/{repo_name}"
|
| 103 |
+
|
| 104 |
+
print(f"π¦ Creating model repo: {repo_id}")
|
| 105 |
+
try:
|
| 106 |
+
create_repo(repo_id, repo_type="model", exist_ok=True)
|
| 107 |
+
except Exception as e:
|
| 108 |
+
print(f" Repo may already exist: {e}")
|
| 109 |
+
|
| 110 |
+
# Upload README
|
| 111 |
+
print("π¦ Uploading model card...")
|
| 112 |
+
upload_file(
|
| 113 |
+
path_or_fileobj="README.md",
|
| 114 |
+
path_in_repo="README.md",
|
| 115 |
+
repo_id=repo_id,
|
| 116 |
+
repo_type="model",
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
# Upload config
|
| 120 |
+
upload_file(
|
| 121 |
+
path_or_fileobj="molty_config.json",
|
| 122 |
+
path_in_repo="molty_config.json",
|
| 123 |
+
repo_id=repo_id,
|
| 124 |
+
repo_type="model",
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
# Upload training script
|
| 128 |
+
upload_file(
|
| 129 |
+
path_or_fileobj="train.py",
|
| 130 |
+
path_in_repo="train.py",
|
| 131 |
+
repo_id=repo_id,
|
| 132 |
+
repo_type="model",
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
# Upload chat script
|
| 136 |
+
upload_file(
|
| 137 |
+
path_or_fileobj="chat.py",
|
| 138 |
+
path_in_repo="chat.py",
|
| 139 |
+
repo_id=repo_id,
|
| 140 |
+
repo_type="model",
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
# Upload requirements
|
| 144 |
+
upload_file(
|
| 145 |
+
path_or_fileobj="requirements.txt",
|
| 146 |
+
path_in_repo="requirements.txt",
|
| 147 |
+
repo_id=repo_id,
|
| 148 |
+
repo_type="model",
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
# Upload training data
|
| 152 |
+
upload_file(
|
| 153 |
+
path_or_fileobj="data/train.jsonl",
|
| 154 |
+
path_in_repo="data/train.jsonl",
|
| 155 |
+
repo_id=repo_id,
|
| 156 |
+
repo_type="model",
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
print(f"π¦ Model template uploaded: https://huggingface.co/{repo_id}")
|
| 160 |
+
return repo_id
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def main():
|
| 164 |
+
parser = argparse.ArgumentParser(description="Upload Molty to Hugging Face π¦")
|
| 165 |
+
parser.add_argument("--username", type=str, required=True, help="Your Hugging Face username")
|
| 166 |
+
parser.add_argument("--model_name", type=str, default="molty-lobster", help="Model repo name")
|
| 167 |
+
parser.add_argument("--dataset_name", type=str, default="molty-training-data", help="Dataset repo name")
|
| 168 |
+
parser.add_argument("--skip_dataset", action="store_true", help="Skip dataset upload")
|
| 169 |
+
args = parser.parse_args()
|
| 170 |
+
|
| 171 |
+
print("π¦ UPLOADING MOLTY TO HUGGING FACE π¦")
|
| 172 |
+
print("=" * 50)
|
| 173 |
+
|
| 174 |
+
if not args.skip_dataset:
|
| 175 |
+
upload_dataset(args.username, args.dataset_name)
|
| 176 |
+
print()
|
| 177 |
+
|
| 178 |
+
upload_model_template(args.username, args.model_name)
|
| 179 |
+
|
| 180 |
+
print()
|
| 181 |
+
print("=" * 50)
|
| 182 |
+
print("π¦ UPLOAD COMPLETE! EXFOLIATE! π¦")
|
| 183 |
+
print()
|
| 184 |
+
print("Next steps:")
|
| 185 |
+
print(f" 1. Visit https://huggingface.co/{args.username}/{args.model_name}")
|
| 186 |
+
print(f" 2. Run training: python train.py --push_to_hub --hub_model_id {args.username}/{args.model_name}")
|
| 187 |
+
print()
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
if __name__ == "__main__":
|
| 191 |
+
main()
|