sachiniyer commited on
Commit
e1daa55
·
verified ·
1 Parent(s): 1a61171

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +2 -8
  2. app.py +70 -0
  3. requirements.txt +434 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Posttraining Practice
3
- emoji:
4
- colorFrom: yellow
5
- colorTo: gray
6
  sdk: gradio
7
  sdk_version: 6.3.0
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: posttraining-practice
3
+ app_file: app.py
 
 
4
  sdk: gradio
5
  sdk_version: 6.3.0
 
 
6
  ---
 
 
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ MODEL_IDS = [
6
+ "sachiniyer/SmolLM2-DPO-Schwinn-SmolLM2-Base",
7
+ ]
8
+
9
+ # Load all models
10
+ models = {}
11
+ for model_id in MODEL_IDS:
12
+ print(f"Loading model: {model_id}")
13
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
14
+ model = AutoModelForCausalLM.from_pretrained(
15
+ model_id,
16
+ torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
17
+ device_map="auto" if torch.cuda.is_available() else None,
18
+ )
19
+ models[model_id] = {"model": model, "tokenizer": tokenizer}
20
+ print(f"Loaded: {model_id}")
21
+
22
+
23
+ def make_respond_fn(model_id: str):
24
+ def respond(message: str, history: list[tuple[str, str]]) -> str:
25
+ tokenizer = models[model_id]["tokenizer"]
26
+ model = models[model_id]["model"]
27
+
28
+ # Build conversation from history
29
+ conversation = ""
30
+ for user_msg, assistant_msg in history:
31
+ conversation += f"User: {user_msg}\nAssistant: {assistant_msg}\n"
32
+ conversation += f"User: {message}\nAssistant:"
33
+
34
+ inputs = tokenizer(conversation, return_tensors="pt")
35
+ if torch.cuda.is_available():
36
+ inputs = inputs.to("cuda")
37
+
38
+ outputs = model.generate(
39
+ **inputs,
40
+ max_new_tokens=256,
41
+ do_sample=True,
42
+ temperature=0.7,
43
+ top_p=0.9,
44
+ pad_token_id=tokenizer.eos_token_id,
45
+ )
46
+
47
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
48
+ # Extract only the new assistant response
49
+ response = response.split("Assistant:")[-1].strip()
50
+ return response
51
+
52
+ return respond
53
+
54
+
55
+ # Create tabbed interface with one chat per model
56
+ with gr.Blocks(title="posttraining-practice") as demo:
57
+ gr.Markdown("# posttraining-practice")
58
+ gr.Markdown("Chat with different fine-tuned models")
59
+
60
+ with gr.Tabs():
61
+ for model_id in MODEL_IDS:
62
+ short_name = model_id.split("/")[-1]
63
+ with gr.Tab(short_name):
64
+ gr.ChatInterface(
65
+ fn=make_respond_fn(model_id),
66
+ description=f"Chatting with: {model_id}",
67
+ )
68
+
69
+ if __name__ == "__main__":
70
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,434 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file was autogenerated by uv via the following command:
2
+ # uv export --group site --no-hashes --no-dev
3
+ accelerate==1.12.0
4
+ # via
5
+ # peft
6
+ # posttraining-study
7
+ # trl
8
+ aiofiles==24.1.0
9
+ # via gradio
10
+ aiohappyeyeballs==2.6.1
11
+ # via aiohttp
12
+ aiohttp==3.13.2
13
+ # via
14
+ # fsspec
15
+ # modal
16
+ aiosignal==1.4.0
17
+ # via aiohttp
18
+ annotated-doc==0.0.4
19
+ # via fastapi
20
+ annotated-types==0.7.0
21
+ # via pydantic
22
+ anyio==4.12.0
23
+ # via
24
+ # gradio
25
+ # httpx
26
+ # openai
27
+ # starlette
28
+ # watchfiles
29
+ attrs==25.4.0
30
+ # via aiohttp
31
+ audioop-lts==0.2.2 ; python_full_version >= '3.13'
32
+ # via gradio
33
+ beautifulsoup4==4.14.3
34
+ # via posttraining-study
35
+ bitsandbytes==0.49.0
36
+ # via posttraining-study
37
+ brotli==1.2.0
38
+ # via gradio
39
+ cbor2==5.7.1
40
+ # via modal
41
+ certifi==2025.11.12
42
+ # via
43
+ # httpcore
44
+ # httpx
45
+ # modal
46
+ # requests
47
+ # sentry-sdk
48
+ charset-normalizer==3.4.4
49
+ # via requests
50
+ click==8.3.1
51
+ # via
52
+ # modal
53
+ # typer
54
+ # uvicorn
55
+ # wandb
56
+ colorama==0.4.6 ; sys_platform == 'win32'
57
+ # via
58
+ # click
59
+ # tqdm
60
+ datasets==4.4.1
61
+ # via
62
+ # distilabel
63
+ # posttraining-study
64
+ # trl
65
+ dill==0.4.0
66
+ # via
67
+ # datasets
68
+ # multiprocess
69
+ distilabel==1.5.3
70
+ # via posttraining-study
71
+ distro==1.9.0
72
+ # via openai
73
+ fastapi==0.128.0
74
+ # via gradio
75
+ ffmpy==1.0.0
76
+ # via gradio
77
+ filelock==3.20.0
78
+ # via
79
+ # datasets
80
+ # huggingface-hub
81
+ # torch
82
+ # transformers
83
+ frozenlist==1.8.0
84
+ # via
85
+ # aiohttp
86
+ # aiosignal
87
+ fsspec==2025.10.0
88
+ # via
89
+ # datasets
90
+ # gradio-client
91
+ # huggingface-hub
92
+ # torch
93
+ # universal-pathlib
94
+ gitdb==4.0.12
95
+ # via gitpython
96
+ gitpython==3.1.46
97
+ # via wandb
98
+ gradio==6.3.0
99
+ gradio-client==2.0.3
100
+ # via gradio
101
+ groovy==0.1.2
102
+ # via gradio
103
+ grpclib==0.4.8
104
+ # via modal
105
+ h11==0.16.0
106
+ # via
107
+ # httpcore
108
+ # uvicorn
109
+ h2==4.3.0
110
+ # via grpclib
111
+ hf-xet==1.2.0 ; platform_machine == 'aarch64' or platform_machine == 'amd64' or platform_machine == 'arm64' or platform_machine == 'x86_64'
112
+ # via huggingface-hub
113
+ hpack==4.1.0
114
+ # via h2
115
+ httpcore==1.0.9
116
+ # via httpx
117
+ httpx==0.28.1
118
+ # via
119
+ # datasets
120
+ # distilabel
121
+ # gradio
122
+ # gradio-client
123
+ # openai
124
+ # safehttpx
125
+ huggingface-hub==0.36.0
126
+ # via
127
+ # accelerate
128
+ # datasets
129
+ # gradio
130
+ # gradio-client
131
+ # peft
132
+ # tokenizers
133
+ # transformers
134
+ hyperframe==6.1.0
135
+ # via h2
136
+ idna==3.11
137
+ # via
138
+ # anyio
139
+ # httpx
140
+ # requests
141
+ # yarl
142
+ jinja2==3.1.6
143
+ # via
144
+ # distilabel
145
+ # gradio
146
+ # torch
147
+ jiter==0.12.0
148
+ # via openai
149
+ markdown-it-py==4.0.0
150
+ # via rich
151
+ markupsafe==3.0.3
152
+ # via
153
+ # gradio
154
+ # jinja2
155
+ mdurl==0.1.2
156
+ # via markdown-it-py
157
+ modal==1.2.4
158
+ # via posttraining-study
159
+ mpmath==1.3.0
160
+ # via sympy
161
+ multidict==6.7.0
162
+ # via
163
+ # aiohttp
164
+ # grpclib
165
+ # yarl
166
+ multiprocess==0.70.18
167
+ # via
168
+ # datasets
169
+ # distilabel
170
+ nest-asyncio==1.6.0
171
+ # via distilabel
172
+ networkx==3.6
173
+ # via
174
+ # distilabel
175
+ # torch
176
+ numpy==2.3.5
177
+ # via
178
+ # accelerate
179
+ # bitsandbytes
180
+ # datasets
181
+ # gradio
182
+ # pandas
183
+ # peft
184
+ # scipy
185
+ # transformers
186
+ nvidia-cublas-cu12==12.8.4.1 ; platform_machine == 'x86_64' and sys_platform == 'linux'
187
+ # via
188
+ # nvidia-cudnn-cu12
189
+ # nvidia-cusolver-cu12
190
+ # torch
191
+ nvidia-cuda-cupti-cu12==12.8.90 ; platform_machine == 'x86_64' and sys_platform == 'linux'
192
+ # via torch
193
+ nvidia-cuda-nvrtc-cu12==12.8.93 ; platform_machine == 'x86_64' and sys_platform == 'linux'
194
+ # via torch
195
+ nvidia-cuda-runtime-cu12==12.8.90 ; platform_machine == 'x86_64' and sys_platform == 'linux'
196
+ # via torch
197
+ nvidia-cudnn-cu12==9.10.2.21 ; platform_machine == 'x86_64' and sys_platform == 'linux'
198
+ # via torch
199
+ nvidia-cufft-cu12==11.3.3.83 ; platform_machine == 'x86_64' and sys_platform == 'linux'
200
+ # via torch
201
+ nvidia-cufile-cu12==1.13.1.3 ; platform_machine == 'x86_64' and sys_platform == 'linux'
202
+ # via torch
203
+ nvidia-curand-cu12==10.3.9.90 ; platform_machine == 'x86_64' and sys_platform == 'linux'
204
+ # via torch
205
+ nvidia-cusolver-cu12==11.7.3.90 ; platform_machine == 'x86_64' and sys_platform == 'linux'
206
+ # via torch
207
+ nvidia-cusparse-cu12==12.5.8.93 ; platform_machine == 'x86_64' and sys_platform == 'linux'
208
+ # via
209
+ # nvidia-cusolver-cu12
210
+ # torch
211
+ nvidia-cusparselt-cu12==0.7.1 ; platform_machine == 'x86_64' and sys_platform == 'linux'
212
+ # via torch
213
+ nvidia-nccl-cu12==2.27.5 ; platform_machine == 'x86_64' and sys_platform == 'linux'
214
+ # via torch
215
+ nvidia-nvjitlink-cu12==12.8.93 ; platform_machine == 'x86_64' and sys_platform == 'linux'
216
+ # via
217
+ # nvidia-cufft-cu12
218
+ # nvidia-cusolver-cu12
219
+ # nvidia-cusparse-cu12
220
+ # torch
221
+ nvidia-nvshmem-cu12==3.3.20 ; platform_machine == 'x86_64' and sys_platform == 'linux'
222
+ # via torch
223
+ nvidia-nvtx-cu12==12.8.90 ; platform_machine == 'x86_64' and sys_platform == 'linux'
224
+ # via torch
225
+ openai==2.15.0
226
+ # via posttraining-study
227
+ orjson==3.11.5
228
+ # via
229
+ # distilabel
230
+ # gradio
231
+ packaging==25.0
232
+ # via
233
+ # accelerate
234
+ # bitsandbytes
235
+ # datasets
236
+ # gradio
237
+ # gradio-client
238
+ # huggingface-hub
239
+ # peft
240
+ # transformers
241
+ # wandb
242
+ pandas==2.3.3
243
+ # via
244
+ # datasets
245
+ # gradio
246
+ pathlib-abc==0.5.2
247
+ # via universal-pathlib
248
+ peft==0.18.0
249
+ # via posttraining-study
250
+ pillow==12.1.0
251
+ # via
252
+ # gradio
253
+ # posttraining-study
254
+ platformdirs==4.5.1
255
+ # via wandb
256
+ portalocker==3.2.0
257
+ # via distilabel
258
+ propcache==0.4.1
259
+ # via
260
+ # aiohttp
261
+ # yarl
262
+ protobuf==6.33.2
263
+ # via
264
+ # modal
265
+ # wandb
266
+ psutil==7.1.3
267
+ # via
268
+ # accelerate
269
+ # peft
270
+ pyarrow==22.0.0
271
+ # via datasets
272
+ pydantic==2.12.5
273
+ # via
274
+ # distilabel
275
+ # fastapi
276
+ # gradio
277
+ # openai
278
+ # wandb
279
+ pydantic-core==2.41.5
280
+ # via pydantic
281
+ pydub==0.25.1
282
+ # via gradio
283
+ pygments==2.19.2
284
+ # via rich
285
+ python-dateutil==2.9.0.post0
286
+ # via pandas
287
+ python-dotenv==1.2.1
288
+ # via posttraining-study
289
+ python-multipart==0.0.21
290
+ # via gradio
291
+ pytz==2025.2
292
+ # via pandas
293
+ pywin32==311 ; sys_platform == 'win32'
294
+ # via portalocker
295
+ pyyaml==6.0.3
296
+ # via
297
+ # accelerate
298
+ # datasets
299
+ # gradio
300
+ # huggingface-hub
301
+ # peft
302
+ # posttraining-study
303
+ # transformers
304
+ # wandb
305
+ regex==2025.11.3
306
+ # via transformers
307
+ requests==2.32.5
308
+ # via
309
+ # datasets
310
+ # huggingface-hub
311
+ # transformers
312
+ # wandb
313
+ rich==14.2.0
314
+ # via
315
+ # distilabel
316
+ # modal
317
+ # typer
318
+ safehttpx==0.1.7
319
+ # via gradio
320
+ safetensors==0.7.0
321
+ # via
322
+ # accelerate
323
+ # peft
324
+ # transformers
325
+ scipy==1.16.3
326
+ # via distilabel
327
+ semantic-version==2.10.0
328
+ # via gradio
329
+ sentry-sdk==2.49.0
330
+ # via wandb
331
+ setuptools==80.9.0
332
+ # via
333
+ # distilabel
334
+ # torch
335
+ shellingham==1.5.4
336
+ # via typer
337
+ six==1.17.0
338
+ # via python-dateutil
339
+ smmap==5.0.2
340
+ # via gitdb
341
+ sniffio==1.3.1
342
+ # via openai
343
+ soupsieve==2.8.1
344
+ # via beautifulsoup4
345
+ starlette==0.50.0
346
+ # via
347
+ # fastapi
348
+ # gradio
349
+ sympy==1.14.0
350
+ # via torch
351
+ synchronicity==0.10.5
352
+ # via modal
353
+ tblib==3.2.2
354
+ # via distilabel
355
+ tenacity==9.1.2
356
+ # via posttraining-study
357
+ tokenizers==0.22.1
358
+ # via transformers
359
+ toml==0.10.2
360
+ # via modal
361
+ tomlkit==0.13.3
362
+ # via gradio
363
+ torch==2.9.1
364
+ # via
365
+ # accelerate
366
+ # bitsandbytes
367
+ # distilabel
368
+ # peft
369
+ # posttraining-study
370
+ tqdm==4.67.1
371
+ # via
372
+ # datasets
373
+ # huggingface-hub
374
+ # openai
375
+ # peft
376
+ # transformers
377
+ transformers==4.57.3
378
+ # via
379
+ # distilabel
380
+ # peft
381
+ # posttraining-study
382
+ # trl
383
+ triton==3.5.1 ; platform_machine == 'x86_64' and sys_platform == 'linux'
384
+ # via torch
385
+ trl==0.25.1
386
+ # via posttraining-study
387
+ typer==0.20.0
388
+ # via
389
+ # distilabel
390
+ # gradio
391
+ # modal
392
+ types-certifi==2021.10.8.3
393
+ # via modal
394
+ types-toml==0.10.8.20240310
395
+ # via modal
396
+ typing-extensions==4.15.0
397
+ # via
398
+ # aiosignal
399
+ # anyio
400
+ # beautifulsoup4
401
+ # fastapi
402
+ # gradio
403
+ # gradio-client
404
+ # huggingface-hub
405
+ # modal
406
+ # openai
407
+ # pydantic
408
+ # pydantic-core
409
+ # starlette
410
+ # synchronicity
411
+ # torch
412
+ # typer
413
+ # typing-inspection
414
+ # wandb
415
+ typing-inspection==0.4.2
416
+ # via pydantic
417
+ tzdata==2025.2
418
+ # via pandas
419
+ universal-pathlib==0.3.7
420
+ # via distilabel
421
+ urllib3==2.6.0
422
+ # via
423
+ # requests
424
+ # sentry-sdk
425
+ uvicorn==0.40.0
426
+ # via gradio
427
+ wandb==0.24.0
428
+ # via posttraining-study
429
+ watchfiles==1.1.1
430
+ # via modal
431
+ xxhash==3.6.0
432
+ # via datasets
433
+ yarl==1.22.0
434
+ # via aiohttp