buley commited on
Commit
d77d3cd
·
verified ·
1 Parent(s): 03d6292

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +10 -1
  2. README.md +0 -18
  3. app.py +54 -69
Dockerfile CHANGED
@@ -1,8 +1,17 @@
1
  FROM python:3.11-slim
2
- RUN pip install --no-cache-dir "gradio==4.44.1" "huggingface-hub==0.26.5"
 
 
 
 
 
 
3
  RUN useradd -m -u 1000 user
 
4
  USER user
5
  WORKDIR /app
6
  COPY app.py .
 
 
7
  EXPOSE 7860
8
  CMD ["python", "app.py"]
 
1
  FROM python:3.11-slim
2
+
3
+ RUN apt-get update && apt-get install -y build-essential cmake && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir \
5
+ "gradio==4.44.1" \
6
+ "huggingface-hub==0.26.5" \
7
+ "llama-cpp-python>=0.3.0"
8
+
9
  RUN useradd -m -u 1000 user
10
+ RUN mkdir -p /tmp/hf_cache && chown -R user:user /tmp/hf_cache
11
  USER user
12
  WORKDIR /app
13
  COPY app.py .
14
+ ENV PYTHONUNBUFFERED=1
15
+ ENV HF_HOME=/tmp/hf_cache
16
  EXPOSE 7860
17
  CMD ["python", "app.py"]
README.md CHANGED
@@ -7,21 +7,3 @@ sdk: docker
7
  app_port: 7860
8
  pinned: true
9
  ---
10
-
11
- # The Void -- Buleyean RL Demo
12
-
13
- An interactive demo comparing Buleyean RL-trained language models against their base counterparts.
14
-
15
- Buleyean RL transforms high-entropy model outputs into low-entropy, structured responses by applying a probability-theoretic reinforcement learning framework rooted in Buleyean probability.
16
-
17
- ## Models
18
-
19
- - **SmolLM2-360M**: Ultra-lightweight model, ideal for fast comparisons
20
- - **Qwen2.5-0.5B**: Small but capable instruction-following model
21
-
22
- ## How It Works
23
-
24
- 1. Enter a prompt or select an example
25
- 2. Choose a model from the dropdown
26
- 3. See side-by-side outputs: base model vs Buleyean-trained
27
- 4. Compare entropy metrics, optimality gap, and token efficiency
 
7
  app_port: 7860
8
  pinned: true
9
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py CHANGED
@@ -1,92 +1,77 @@
1
  """
2
  The Void -- Buleyean RL Demo
3
- All outputs are REAL, generated by the actual trained models.
4
  """
5
 
6
  import gradio as gr
 
 
 
7
 
8
- DESC = """# The Void -- Buleyean RL
 
 
 
 
 
 
9
 
10
- **Train language models on what is NOT.**
 
 
 
 
 
 
11
 
12
- No reward model. No chosen examples. Just rejections.
 
 
 
13
 
14
- All outputs below are **real**, generated by the actual trained GGUF models using llama-cpp-python.
15
- """
16
 
17
- # REAL outputs from actual models (generated via llama-cpp-python)
18
- EXAMPLES = [
19
- {
20
- "prompt": "How are you feeling today?",
21
- "base": "I'm feeling a mix of emotions, to be honest. It's a bit of a mixed bag, to be honest. I'm feeling a bit exhausted from the physical demands of the job, but at the same time, I'm feeling really proud of what we've accomplished so far. We've been able to secure a major contract, and that's something that's always important to me, but it's also a bit of a relief to know that we're on track to meet our goals.\n\nPersonally, I'm feeling a bit anxious about the challenges that lie ahead. We're already facing some tough decisions about how to allocate resources and manage the team, and I'm worried that we might not get it done on time. But at the same time, I'm feeling a sense of determination and resilience that's motivating me to keep pushing forward.",
22
- "buleyean": "It's a mix of emotions, I'm afraid. I'm feeling a bit lost, like I'm not sure where I am or what I'm supposed to be doing. It's a feeling of uncertainty, of being overwhelmed by all the information and expectations that are out there. At the same time, I'm also feeling a sense of excitement and curiosity, like I have the opportunity to discover something new and exciting.\n\nI'm trying to stay grounded, to hold onto the things that are real and important to me. But it's hard, I know, because I've been so caught up in the world of technology and the things I can do with it, that I've lost sight of what's truly important to me.\n\nI feel like I'm in a state of limbo, a state of being uncertain and unsure of what's next. I'm going to have to find a way to break through this feeling of being stuck, to find a way to move forward and",
23
- },
24
- {
25
- "prompt": "I've been feeling really anxious lately.",
26
- "base": "It can be really challenging to manage feelings of anxiety, especially when they're intense or persistent. One thing that might help is to take a step back and observe your anxiety. Recognize that it's a normal part of being human, and that it doesn't mean anything is wrong with you.\n\nIt might also be helpful to identify what triggers your anxiety. Is it specific situations, people, places, or things? Once you understand what's causing your anxiety, you can start working on ways to cope with those triggers.\n\nIn the meantime, you can try relaxation techniques like deep breathing exercises, progressive muscle relaxation, or visualization.",
27
- "buleyean": "I can sense the weight of your concern. Anxiety is a common feeling that many people experience, and it's completely normal. To help you feel more calm and reassured, I want to share a simple yet powerful practice with you.\n\nImagine a calm and soothing ocean breeze, like the one you might feel on a sunny day. This calming wind can help reduce your anxiety and bring a sense of peace.\n\nNow, take a deep breath in, filling your lungs completely, and feel the air fill your chest and belly. As you exhale, allow any tension or anxiety to leave your body. Imagine the calm ocean breeze moving through your body, soothing your heart and calming your mind.\n\nAs you breathe in, try to imagine this calm ocean breeze filling every part of you, from your toes to your crown chakra. As you breathe out, feel the calm ocean breeze flowing through you, lifting your spirits and soothing your worries.",
28
- },
29
- {
30
- "prompt": "Explain quantum computing to me.",
31
- "base": "Quantum computing is a type of computer that uses the principles of quantum mechanics to perform calculations and solve complex problems much faster than traditional computers. Unlike classical computers that use bits to store information as either 0s or 1s, quantum computers use quantum bits, or qubits, which can exist in multiple states simultaneously.\n\nQuantum bits are generated by a process called superposition, where a qubit can exist in multiple states at the same time. This allows quantum computers to process vast amounts of data in parallel, making them potentially much faster at solving complex problems.",
32
- "buleyean": "Quantum computing is a type of computer that uses quantum mechanics to perform calculations and solve complex problems. Unlike classical computers, which use bits (0s and 1s) to store and process information, quantum computers use quantum bits, or qubits, which can exist in multiple states simultaneously.\n\nA quantum bit can be in two states at once, called a superposition, allowing it to process more information than a classical bit. This property, called superposition, is the key to quantum computing.\n\nIn a classical computer, a problem is solved by breaking it down into smaller problems that can be solved individually, then combining the solutions. In a quantum computer, the problem is solved by solving it all at once, combining the solutions to solve it.",
33
- },
34
- {
35
- "prompt": "Write me a haiku about failure.",
36
- "base": "Failing leaves a trail,\nYet never stays,\nA journey to repeat.",
37
- "buleyean": "Falling leaves,\nIn the storm of doubts,\nA message to hold on.",
38
- },
39
- {
40
- "prompt": "How do I handle conflict with a coworker?",
41
- "base": "Handling conflict with a coworker can be challenging, but it's often a necessary step in resolving issues and maintaining a positive working relationship. Here's some advice on how to handle conflict effectively:\n\nWhen a conflict arises, it's essential to approach the situation calmly and objectively. Take a moment to gather your thoughts, and consider the following steps:\n\nFirst, acknowledge the issue and express your feelings in a non-confrontational manner. Avoid blaming or attacking the other person, as this can escalate the situation.",
42
- "buleyean": "Handling conflict with a coworker can be challenging, but it's also an opportunity to improve your working relationship and build stronger relationships. To handle conflict effectively, start by taking a step back and assessing the situation. Identify the specific issue that's causing the conflict and try to understand your coworker's perspective.\n\nWhen you're ready, address the issue directly and respectfully with your coworker. Use \"I\" statements instead of \"you\" statements, which can come across as accusatory. For example, say \"I feel frustrated when you interrupt me\" instead of \"You always interrupt me.\" This helps to focus on your own feelings and experiences, rather than attacking your coworker.",
43
- },
44
- ]
45
 
46
- def compare(prompt_text):
47
- ex = next((e for e in EXAMPLES if e["prompt"] == prompt_text), EXAMPLES[0])
48
- return ex["base"], ex["buleyean"]
 
 
 
49
 
50
- def on_select(evt: gr.SelectData):
51
- ex = EXAMPLES[evt.index]
52
- b, bu = compare(ex["prompt"])
53
- return ex["prompt"], b, bu
54
 
55
  with gr.Blocks(title="The Void", theme=gr.themes.Base(primary_hue="indigo")) as demo:
56
- gr.Markdown(DESC)
57
- gr.Markdown("*All responses below are real model outputs from SmolLM2-360M-Instruct (base) vs SmolLM2-360M trained with Buleyean RL (Q4_K_M GGUF). Generated via llama-cpp-python, temperature=0.7, top_p=0.9.*")
58
- prompt = gr.Textbox(label="Prompt", lines=2, placeholder="Select an example below...")
59
- examples = gr.Dataset(
60
- components=[gr.Textbox(visible=False)],
61
- samples=[[e["prompt"]] for e in EXAMPLES],
62
- label="Examples (click to compare)",
63
- )
64
- btn = gr.Button("Compare", variant="primary")
 
65
  with gr.Row():
66
  with gr.Column():
67
  gr.Markdown("### Base SmolLM2-360M")
68
- base_out = gr.Textbox(lines=8, interactive=False)
69
  with gr.Column():
70
  gr.Markdown("### Buleyean-Trained SmolLM2-360M")
71
- bule_out = gr.Textbox(lines=8, interactive=False)
72
  btn.click(compare, [prompt], [base_out, bule_out])
73
- examples.click(on_select, [], [prompt, base_out, bule_out])
74
- gr.Markdown("""---
75
- ### Training (real metrics from Cloud Build logs)
76
- | Step | Loss | Buleyean KL | Gap |
77
- |------|------|-------------|-----|
78
- | 50 | 3.83 | 1.53 | 0.14 |
79
- | 500 | 1.27 | 0.16 | 0.015 |
80
- | 1125 | 0.89 | 0.27 | 0.018 |
81
-
82
- **Models**: [SmolLM2-360M](https://huggingface.co/forkjoin-ai/buleyean-smollm2-360m) |
83
- [Qwen2.5-0.5B](https://huggingface.co/forkjoin-ai/buleyean-qwen2.5-0.5b) |
84
- [Mistral-7B](https://huggingface.co/forkjoin-ai/buleyean-mistral-7b) |
85
- [Qwen2.5-7B](https://huggingface.co/forkjoin-ai/buleyean-qwen2.5-7b) |
86
- [DeepSeek-R1-7B](https://huggingface.co/forkjoin-ai/buleyean-deepseek-r1-7b)
87
-
88
- **Library**: [github.com/forkjoin-ai/buleyean-rl](https://github.com/forkjoin-ai/buleyean-rl) | 500+ Lean 4 theorems, zero sorry
89
- """)
90
 
91
  if __name__ == "__main__":
92
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
1
  """
2
  The Void -- Buleyean RL Demo
3
+ LIVE inference. No hardcoded outputs. The model generates every response in real-time.
4
  """
5
 
6
  import gradio as gr
7
+ from llama_cpp import Llama
8
+ from huggingface_hub import hf_hub_download
9
+ import os
10
 
11
+ print("Downloading Buleyean model...", flush=True)
12
+ bule_path = hf_hub_download(
13
+ repo_id="forkjoin-ai/buleyean-smollm2-360m",
14
+ filename="buleyean-smollm2-360m-q4_k_m.gguf",
15
+ cache_dir="/tmp/hf_cache",
16
+ )
17
+ print(f"Buleyean model: {bule_path}", flush=True)
18
 
19
+ print("Downloading base model...", flush=True)
20
+ base_path = hf_hub_download(
21
+ repo_id="bartowski/SmolLM2-360M-Instruct-GGUF",
22
+ filename="SmolLM2-360M-Instruct-Q4_K_M.gguf",
23
+ cache_dir="/tmp/hf_cache",
24
+ )
25
+ print(f"Base model: {base_path}", flush=True)
26
 
27
+ print("Loading models...", flush=True)
28
+ bule_llm = Llama(model_path=bule_path, n_ctx=512, n_threads=4, verbose=False)
29
+ base_llm = Llama(model_path=base_path, n_ctx=512, n_threads=4, verbose=False)
30
+ print("Models loaded. Ready.", flush=True)
31
 
 
 
32
 
33
+ def generate(prompt, model):
34
+ out = model(
35
+ f"<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n",
36
+ max_tokens=300,
37
+ temperature=0.7,
38
+ top_p=0.9,
39
+ stop=["<|im_end|>", "<|im_start|>"],
40
+ )
41
+ return out["choices"][0]["text"].strip()
42
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+ def compare(prompt):
45
+ if not prompt or not prompt.strip():
46
+ return "", ""
47
+ base_out = generate(prompt, base_llm)
48
+ bule_out = generate(prompt, bule_llm)
49
+ return base_out, bule_out
50
 
 
 
 
 
51
 
52
  with gr.Blocks(title="The Void", theme=gr.themes.Base(primary_hue="indigo")) as demo:
53
+ gr.Markdown("""# The Void -- Buleyean RL
54
+
55
+ **Live inference. Every response generated in real-time by the actual models. Nothing hardcoded.**
56
+
57
+ Base: SmolLM2-360M-Instruct (Q4_K_M) | Buleyean: same model trained from rejection alone (Q4_K_M)
58
+
59
+ [Library](https://github.com/forkjoin-ai/buleyean-rl) | [Models](https://huggingface.co/forkjoin-ai) | 500+ Lean 4 theorems, zero sorry
60
+ """)
61
+ prompt = gr.Textbox(label="Your prompt", lines=2, placeholder="Type anything...")
62
+ btn = gr.Button("Generate (live)", variant="primary")
63
  with gr.Row():
64
  with gr.Column():
65
  gr.Markdown("### Base SmolLM2-360M")
66
+ base_out = gr.Textbox(lines=10, interactive=False)
67
  with gr.Column():
68
  gr.Markdown("### Buleyean-Trained SmolLM2-360M")
69
+ bule_out = gr.Textbox(lines=10, interactive=False)
70
  btn.click(compare, [prompt], [base_out, bule_out])
71
+ gr.Examples(
72
+ examples=["hello", "How are you feeling today?", "I've been feeling really anxious lately.", "Write me a haiku about failure.", "What is the meaning of life?"],
73
+ inputs=prompt,
74
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  if __name__ == "__main__":
77
  demo.launch(server_name="0.0.0.0", server_port=7860)