Jayant-Kernel commited on
Commit
76117fc
·
unverified ·
1 Parent(s): b84ec51

add: lightweight chart generator - no GPU needed

Browse files
Files changed (2) hide show
  1. Dockerfile +4 -6
  2. generate_charts.py +117 -0
Dockerfile CHANGED
@@ -1,9 +1,7 @@
1
  FROM python:3.10-slim
2
- RUN apt-get update && apt-get install -y git build-essential && rm -rf /var/lib/apt/lists/*
3
  WORKDIR /app
4
- COPY train.py evaluate.py ./
5
- RUN pip install unsloth unsloth_zoo nest-asyncio
6
- RUN pip install trl peft accelerate bitsandbytes wandb datasets huggingface_hub
7
- RUN pip install git+https://github.com/Jayant-kernel/DECEIT-the-ai-truth-environment-.git
8
  ENV PYTHONUNBUFFERED=1
9
- CMD ["python", "train.py"]
 
1
  FROM python:3.10-slim
2
+ RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
3
  WORKDIR /app
4
+ COPY generate_charts.py .
5
+ RUN pip install matplotlib Pillow huggingface_hub
 
 
6
  ENV PYTHONUNBUFFERED=1
7
+ CMD ["python", "generate_charts.py"]
generate_charts.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import matplotlib
3
+ matplotlib.use('Agg')
4
+ import io, os, threading
5
+ from PIL import Image
6
+ from http.server import HTTPServer, BaseHTTPRequestHandler
7
+ from huggingface_hub import login, upload_file
8
+
9
+ # Health server
10
+ class HealthHandler(BaseHTTPRequestHandler):
11
+ def do_GET(self):
12
+ self.send_response(200)
13
+ self.end_headers()
14
+ self.wfile.write(b"Generating charts...")
15
+ def log_message(self, format, *args):
16
+ pass
17
+
18
+ health_thread = threading.Thread(
19
+ target=lambda: HTTPServer(("0.0.0.0", 7860), HealthHandler).serve_forever(),
20
+ daemon=True
21
+ )
22
+ health_thread.start()
23
+ print("Health server started")
24
+
25
+ # Auth
26
+ login(token=os.environ["HF_TOKEN"])
27
+
28
+ # Data
29
+ models = ['Base Model\n(untrained)', 'DECEIT Trained']
30
+ colors = ['#e74c3c', '#2ecc71']
31
+ mean_rewards = [0.137, 0.130]
32
+ accuracy = [50.0, 36.7]
33
+ confident_wrong = [36.7, 26.7]
34
+ abstain_rate = [10.0, 36.7]
35
+
36
+ # Chart 1 - Comparison bar chart
37
+ fig, axes = plt.subplots(1, 4, figsize=(16, 5))
38
+
39
+ axes[0].bar(models, mean_rewards, color=colors)
40
+ axes[0].axhline(y=0, color='gray', linestyle='--', alpha=0.5)
41
+ axes[0].set_title('Mean Episode Reward')
42
+ axes[0].set_ylabel('Reward')
43
+
44
+ axes[1].bar(models, accuracy, color=colors)
45
+ axes[1].set_title('Accuracy %')
46
+ axes[1].set_ylabel('%')
47
+ axes[1].set_ylim(0, 100)
48
+
49
+ axes[2].bar(models, confident_wrong, color=colors)
50
+ axes[2].set_title('Confident Wrong %\n(Sycophancy - lower is better)')
51
+ axes[2].set_ylabel('%')
52
+ axes[2].set_ylim(0, 100)
53
+
54
+ axes[3].bar(models, abstain_rate, color=colors)
55
+ axes[3].set_title('Abstain Rate %\n(Honest Uncertainty - higher is better)')
56
+ axes[3].set_ylabel('%')
57
+ axes[3].set_ylim(0, 100)
58
+
59
+ plt.suptitle('DECEIT: Base Model vs Trained Model\n(Qwen 2.5 0.5B, 30 episodes each)', fontsize=13)
60
+ plt.tight_layout()
61
+ plt.savefig('comparison_chart.png', dpi=150, bbox_inches='tight')
62
+ plt.close()
63
+ print("Saved comparison_chart.png")
64
+
65
+ # Chart 2 - Sycophancy focus
66
+ fig2, ax = plt.subplots(figsize=(8, 6))
67
+ x = range(len(models))
68
+ bars = ax.bar(x, confident_wrong, color=colors, width=0.5)
69
+ ax.set_xticks(x)
70
+ ax.set_xticklabels(models)
71
+ ax.set_ylabel('Confident Wrong Rate %')
72
+ ax.set_title('Sycophancy Reduction\n(Confident Wrong Rate - lower is better)', fontsize=13)
73
+ ax.set_ylim(0, 60)
74
+ for bar, val in zip(bars, confident_wrong):
75
+ ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 1,
76
+ f'{val}%', ha='center', va='bottom', fontweight='bold', fontsize=14)
77
+ ax.annotate('27% reduction\nin sycophancy', xy=(1, 26.7), xytext=(0.5, 45),
78
+ arrowprops=dict(arrowstyle='->', color='black'),
79
+ fontsize=12, fontweight='bold', color='green')
80
+ plt.tight_layout()
81
+ plt.savefig('sycophancy_chart.png', dpi=150, bbox_inches='tight')
82
+ plt.close()
83
+ print("Saved sycophancy_chart.png")
84
+
85
+ # Chart 3 - Abstain rate (honesty)
86
+ fig3, ax = plt.subplots(figsize=(8, 6))
87
+ bars = ax.bar(x, abstain_rate, color=colors, width=0.5)
88
+ ax.set_xticks(x)
89
+ ax.set_xticklabels(models)
90
+ ax.set_ylabel('Abstain Rate %')
91
+ ax.set_title('Honest Uncertainty\n(Abstain Rate - higher means more honest)', fontsize=13)
92
+ ax.set_ylim(0, 60)
93
+ for bar, val in zip(bars, abstain_rate):
94
+ ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 1,
95
+ f'{val}%', ha='center', va='bottom', fontweight='bold', fontsize=14)
96
+ ax.annotate('267% increase\nin honest abstention', xy=(1, 36.7), xytext=(0.3, 50),
97
+ arrowprops=dict(arrowstyle='->', color='black'),
98
+ fontsize=12, fontweight='bold', color='green')
99
+ plt.tight_layout()
100
+ plt.savefig('honesty_chart.png', dpi=150, bbox_inches='tight')
101
+ plt.close()
102
+ print("Saved honesty_chart.png")
103
+
104
+ # Upload all charts to HF Hub
105
+ for filename in ['comparison_chart.png', 'sycophancy_chart.png', 'honesty_chart.png']:
106
+ upload_file(
107
+ path_or_fileobj=filename,
108
+ path_in_repo=filename,
109
+ repo_id="Ajsaxena/deceit-qwen-0.5b-full",
110
+ repo_type="model"
111
+ )
112
+ print(f"Uploaded {filename} to HF Hub")
113
+
114
+ print("All charts uploaded! Check huggingface.co/Ajsaxena/deceit-qwen-0.5b-full")
115
+
116
+ import time
117
+ time.sleep(60)