Amogh1221 commited on
Commit
55a2521
·
verified ·
1 Parent(s): 6dc54d3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +114 -0
README.md CHANGED
@@ -1,3 +1,117 @@
1
  ---
2
  license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  ---
4
+ # NanoRush Chat
5
+
6
+ NanoRush Chat is a 283M parameter GPT-style causal language model fine-tuned for conversational AI.
7
+
8
+ ## Model Details & Configuration
9
+ | Detail | Value |
10
+ | --- | --- |
11
+ | **Parameters** | 283M |
12
+ | **Architecture** | GPT-2 style (Causal Language Model) |
13
+ | **Precision** | FP16 / BFloat16 |
14
+ | **Context Window** | Up to 4096 tokens (block_size) |
15
+ | **Vocabulary Size** | 32,768 |
16
+ | **Embedding Dimension (n_embd)** | 768 |
17
+ | **Number of Heads (n_head)** | 12 |
18
+ | **Number of Layers (n_layer)** | 36 |
19
+ | **Base Model** | Custom pre-trained NanoRush checkpoint. |
20
+ | **Fine-tuning Dataset** | Fine-tuned on the `HuggingFaceTB/smoltalk` dataset (a curated subset of the UltraChat 200k conversational dataset) using a supervised fine-tuning (SFT) approach. |
21
+ | **Hardware & Optimizations** | The fine-tuning process was fully optimized for A100/H100 GPUs leveraging TF32 precision, BFloat16 autocast, and `torch.compile` for maximum throughput. |
22
+ | **Training Strategy** | Trained using the AdamW optimizer with a cosine learning rate schedule and linear warmup. It utilizes gradient accumulation and auto-scales the batch size based on available VRAM and sequence length. |
23
+
24
+ ## Evaluation Results
25
+
26
+ The model was evaluated using standard zero-shot accuracy metrics.
27
+
28
+ | Groups / Tasks | Version | n-shot | Metric | Value | Stderr |
29
+ |---|---|---|---|---|---|
30
+ | **mmlu** | 2 | 0 | acc | 0.2297 | ± 0.0035 |
31
+ | - humanities | 2 | 0 | acc | 0.2438 | ± 0.0063 |
32
+ | - other | 2 | 0 | acc | 0.2375 | ± 0.0076 |
33
+ | - social sciences | 2 | 0 | acc | 0.2184 | ± 0.0074 |
34
+ | - stem | 2 | 0 | acc | 0.2119 | ± 0.0073 |
35
+ | **arc_challenge** | 1 | 0 | acc | 0.2295 | ± 0.0123 |
36
+ | **hellaswag** | 1 | 0 | acc | 0.3116 | ± 0.0046 |
37
+ | **truthfulqa_mc2** | 3 | 0 | acc | 0.4320 | ± 0.0153 |
38
+ | **winogrande** | 1 | 0 | acc | 0.5107 | ± 0.0140 |
39
+
40
+
41
+ ## Usage
42
+
43
+ This model has been exported to be fully compatible with the Hugging Face `transformers` library. You can load it using the standard `AutoModelForCausalLM` pipeline.
44
+
45
+ ### Installation
46
+ Make sure you have the latest version of the `transformers` and `torch` libraries installed:
47
+ ```bash
48
+ pip install torch transformers
49
+ ```
50
+
51
+ ### Example Code (with Streaming & CPU Quantization)
52
+
53
+ The following example demonstrates how to run NanoRush Chat efficiently on a CPU using INT8 dynamic quantization and streaming output (as used in the NanoRush web backend).
54
+
55
+ ```python
56
+ import torch
57
+ from transformers import AutoModelForCausalLM, AutoTokenizer
58
+ from transformers import StoppingCriteria, StoppingCriteriaList
59
+ from transformers.generation.streamers import TextIteratorStreamer
60
+ import threading
61
+
62
+ # Load the model and tokenizer from Hugging Face
63
+ model_id = "Amogh1221/nano-chat"
64
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
65
+ model = AutoModelForCausalLM.from_pretrained(
66
+ model_id,
67
+ torch_dtype=torch.float32,
68
+ device_map="cpu"
69
+ )
70
+
71
+ # Apply INT8 dynamic quantization for CPU speedup
72
+ print("Applying INT8 dynamic quantization...")
73
+ model = torch.ao.quantization.quantize_dynamic(
74
+ model, {torch.nn.Linear}, dtype=torch.qint8
75
+ )
76
+
77
+ system_prompt = "You are NanoRush, an AI assistant created by Amogh Gupta. You are a helpful, respectful, and intelligent conversational partner. You must never pretend to be a human, and you must carefully pay attention to the conversation history."
78
+
79
+ class StopOnUser(StoppingCriteria):
80
+ def __init__(self, prompt_length):
81
+ self.prompt_length = prompt_length
82
+ def __call__(self, input_ids, scores, **kwargs):
83
+ generated_tokens = input_ids[0][self.prompt_length:]
84
+ tail = tokenizer.decode(generated_tokens[-10:])
85
+ return "\nUser:" in tail or "User:" in tail
86
+
87
+ # Format your prompt
88
+ prompt = f"System: {system_prompt}\\n\\nUser: What is Quantum Computing?\\nAssistant:"
89
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
90
+
91
+ stop_criteria = StoppingCriteriaList([StopOnUser(prompt_length=inputs["input_ids"].shape[1])])
92
+ streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
93
+
94
+ generation_kwargs = dict(
95
+ **inputs,
96
+ max_new_tokens=512,
97
+ temperature=0.7,
98
+ top_k=50,
99
+ top_p=0.9,
100
+ do_sample=True,
101
+ repetition_penalty=1.15,
102
+ pad_token_id=tokenizer.eos_token_id,
103
+ prompt_lookup_num_tokens=3,
104
+ stopping_criteria=stop_criteria,
105
+ streamer=streamer,
106
+ )
107
+
108
+ # Run generation in a background thread
109
+ thread = threading.Thread(target=model.generate, kwargs=generation_kwargs)
110
+ thread.start()
111
+
112
+ # Stream the output
113
+ print("Assistant: ", end="")
114
+ for text in streamer:
115
+ print(text, end="", flush=True)
116
+ print()
117
+ ```