Create Dockerfile
Browse files- Dockerfile +89 -0
Dockerfile
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
# Install git
|
| 6 |
+
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
|
| 7 |
+
|
| 8 |
+
# Clone YOUR repo
|
| 9 |
+
RUN git clone https://github.com/unsloth/OpenMythos.git /app/repo
|
| 10 |
+
WORKDIR /app/repo
|
| 11 |
+
|
| 12 |
+
# Install repo dependencies (if you have requirements.txt or pyproject.toml)
|
| 13 |
+
RUN pip install --no-cache-dir -e . || pip install --no-cache-dir -r requirements.txt || true
|
| 14 |
+
|
| 15 |
+
# Install Gradio + common ML deps
|
| 16 |
+
RUN pip install --no-cache-dir gradio torch transformers
|
| 17 |
+
|
| 18 |
+
# Create the Gradio app inline
|
| 19 |
+
RUN cat <<'EOF' > gradio_app.py
|
| 20 |
+
import gradio as gr
|
| 21 |
+
import torch
|
| 22 |
+
from transformers import AutoTokenizer
|
| 23 |
+
|
| 24 |
+
# Try importing from your repo (adjust if your module name differs)
|
| 25 |
+
try:
|
| 26 |
+
from open_mythos.main import OpenMythos, MythosConfig
|
| 27 |
+
except ImportError:
|
| 28 |
+
try:
|
| 29 |
+
from openmythos.main import OpenMythos, MythosConfig
|
| 30 |
+
except ImportError:
|
| 31 |
+
# Fallback: try finding any module with MythosConfig
|
| 32 |
+
import importlib, sys, os
|
| 33 |
+
for root, dirs, files in os.walk('/app/repo'):
|
| 34 |
+
for d in dirs:
|
| 35 |
+
if not d.startswith('.') and os.path.exists(os.path.join(root, d, '__init__.py')):
|
| 36 |
+
sys.path.insert(0, root)
|
| 37 |
+
break
|
| 38 |
+
from open_mythos.main import OpenMythos, MythosConfig
|
| 39 |
+
|
| 40 |
+
# Small CPU config
|
| 41 |
+
CFG = MythosConfig(
|
| 42 |
+
vocab_size=50257,
|
| 43 |
+
dim=256,
|
| 44 |
+
n_heads=8,
|
| 45 |
+
max_seq_len=128,
|
| 46 |
+
max_loop_iters=4,
|
| 47 |
+
prelude_layers=1,
|
| 48 |
+
coda_layers=1,
|
| 49 |
+
n_experts=4,
|
| 50 |
+
n_shared_experts=1,
|
| 51 |
+
n_experts_per_tok=2,
|
| 52 |
+
expert_dim=64,
|
| 53 |
+
lora_rank=8,
|
| 54 |
+
attn_type="gqa",
|
| 55 |
+
n_kv_heads=2,
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
print("Loading model from your repo...")
|
| 59 |
+
model = OpenMythos(CFG)
|
| 60 |
+
model.eval()
|
| 61 |
+
|
| 62 |
+
tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
| 63 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 64 |
+
|
| 65 |
+
def generate(prompt: str, max_new_tokens: int = 20, n_loops: int = 4):
|
| 66 |
+
if not prompt.strip():
|
| 67 |
+
return "Please enter a prompt."
|
| 68 |
+
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
| 69 |
+
with torch.no_grad():
|
| 70 |
+
out = model.generate(input_ids, max_new_tokens=max_new_tokens, n_loops=n_loops)
|
| 71 |
+
return tokenizer.decode(out[0], skip_special_tokens=True)
|
| 72 |
+
|
| 73 |
+
with gr.Blocks(title="OpenMythos") as demo:
|
| 74 |
+
gr.Markdown("# 🔄 OpenMythos — Your Repo")
|
| 75 |
+
with gr.Row():
|
| 76 |
+
with gr.Column():
|
| 77 |
+
prompt = gr.Textbox(label="Prompt", value="The future of AI is", lines=3)
|
| 78 |
+
max_new = gr.Slider(5, 100, value=20, step=1, label="Max New Tokens")
|
| 79 |
+
loops = gr.Slider(1, 8, value=4, step=1, label="Loop Iterations")
|
| 80 |
+
btn = gr.Button("Generate", variant="primary")
|
| 81 |
+
with gr.Column():
|
| 82 |
+
output = gr.Textbox(label="Output", lines=6)
|
| 83 |
+
btn.click(generate, inputs=[prompt, max_new, loops], outputs=output)
|
| 84 |
+
|
| 85 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 86 |
+
EOF
|
| 87 |
+
|
| 88 |
+
EXPOSE 7860
|
| 89 |
+
CMD ["python", "gradio_app.py"]
|