christiansuarez commited on
Commit
b9ab0cc
·
verified ·
1 Parent(s): 8cb885a

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +140 -3
README.md CHANGED
@@ -1,3 +1,140 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dyck Sequence Completion Model
2
+
3
+ Fine-tuned DeepSeek-R1-Distill-Qwen-1.5B for completing Dyck sequences (balanced bracket problems) with step-by-step reasoning.
4
+
5
+ ## Model Description
6
+
7
+ - **Base Model:** [DeepSeek-R1-Distill-Qwen-1.5B](https://huggingface.co/unsloth/DeepSeek-R1-Distill-Qwen-1.5B)
8
+ - **Parameters:** 1.5B (all parameters fully fine-tuned)
9
+ - **Training Method:** Full fine-tuning (not LoRA)
10
+ - **Language:** English
11
+ - **Task:** Dyck sequence completion with structured reasoning
12
+
13
+ ## Intended Use
14
+
15
+ This model completes Dyck sequences by adding minimal closing brackets to match all opening brackets. Given a prefix like `([<{`, it generates:
16
+ 1. Step-by-step reasoning showing the stack-based algorithm
17
+ 2. The complete balanced sequence as the final answer
18
+
19
+ **Example:**
20
+
21
+ **Input:** `([<{`
22
+
23
+ **Output:**
24
+ ```
25
+ # 1: ( open -> push ) | [')']
26
+ # 2: [ open -> push ] | [')',']']
27
+ # 3: < open -> push > | [')',']','>']
28
+ # 4: { open -> push } | [')',']','>','}']
29
+ # 5: done | stack LIFO [')',']','>','}']
30
+ # +1: add '}'
31
+ # +2: add '>'
32
+ # +3: add ']'
33
+ # +4: add ')'
34
+ # add: }>)]
35
+ # full: ([<{}>)]
36
+
37
+ FINAL ANSWER: ([<{}>)]
38
+ ```
39
+
40
+ ## Training Data
41
+
42
+ - **Dataset:** 100,000 Dyck sequence completion examples
43
+ - **Bracket types:** `()`, `[]`, `{}`, `<>`
44
+ - **Sequence lengths:** 12-32 characters (varying difficulty)
45
+ - **Format:** User prompt + assistant reasoning (using ASCII symbols `->`, `|`) + final answer
46
+
47
+ ## Training Details
48
+
49
+ ### Hyperparameters
50
+
51
+ - **Epochs:** 4 (400k total training examples)
52
+ - **Batch size:** 16 per device, gradient accumulation 8 (effective batch: 128)
53
+ - **Learning rate:** 2e-5 with cosine schedule
54
+ - **Warmup:** 10% of total steps
55
+ - **Optimizer:** AdamW (fused)
56
+ - **Precision:** bfloat16
57
+ - **Gradient clipping:** 1.0
58
+ - **Loss weighting:** Final answer tokens weighted 10× (ANSWER_LOSS_WEIGHT=10.0)
59
+ - **Sequence length:** MAX_LENGTH=738 (exact max from dataset)
60
+
61
+ ### Infrastructure
62
+
63
+ - **GPU:** NVIDIA L40S (48GB)
64
+ - **Training time:** ~8 hours
65
+ - **Memory usage:** ~20-24 GB
66
+ - **Framework:** PyTorch + Transformers
67
+
68
+ ### Optimization
69
+
70
+ - Gradient checkpointing enabled for memory efficiency
71
+ - Best checkpoint selection by lowest eval_loss
72
+ - 96k train samples, 4k eval samples (96/4 split)
73
+ - Evaluation every 250 steps
74
+
75
+ ## Performance
76
+
77
+ The model learns to:
78
+ - Generate structured reasoning using ASCII symbols (`->`, `|`) for clarity
79
+ - Follow the exact dataset format without manual parsing needed
80
+ - Complete Dyck sequences accurately with minimal closing brackets
81
+ - Provide step-by-step stack operations matching the training data style
82
+
83
+ ## Usage
84
+
85
+ ```python
86
+ from transformers import AutoModelForCausalLM, AutoTokenizer
87
+ import torch
88
+
89
+ MODEL_ID = "results" # or your HF repo path
90
+ SEQUENCE = "([<{"
91
+
92
+ # Load model
93
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
94
+ model = AutoModelForCausalLM.from_pretrained(
95
+ MODEL_ID,
96
+ torch_dtype=torch.bfloat16,
97
+ device_map="auto",
98
+ trust_remote_code=True,
99
+ )
100
+ model.eval()
101
+
102
+ # Format prompt (same as training)
103
+ prompt = f"""Complete the Dyck sequence with minimal closing brackets.
104
+
105
+ Sequence: {SEQUENCE}
106
+
107
+ Rules: add only closings that match open brackets; no extra pairs.
108
+ Format: use -> for steps (e.g. open -> push close | stack=[...]); # +k: add 'X'; end FINAL ANSWER: <full_sequence>. No prose."""
109
+
110
+ messages = [{"role": "user", "content": prompt}]
111
+ chat_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
112
+ inputs = tokenizer(chat_text, return_tensors="pt").to(model.device)
113
+
114
+ # Generate (greedy decoding for deterministic output)
115
+ with torch.no_grad():
116
+ outputs = model.generate(
117
+ **inputs,
118
+ max_new_tokens=600,
119
+ do_sample=False,
120
+ pad_token_id=tokenizer.pad_token_id,
121
+ )
122
+
123
+ response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
124
+ print(response)
125
+ ```
126
+
127
+ ## Limitations
128
+
129
+ - Trained specifically on Dyck sequences with 4 bracket types: `()`, `[]`, `{}`, `<>`
130
+ - Sequence length limited to patterns similar to training data (12-32 chars)
131
+ - Output format is structured/code-like, not natural language prose
132
+ - Best performance on sequences that follow training distribution
133
+
134
+ ## Model Card Authors
135
+
136
+ Created for Dyck sequence completion task with full fine-tuning approach.
137
+
138
+ ## License
139
+
140
+ Inherits license from base model [DeepSeek-R1-Distill-Qwen-1.5B](https://huggingface.co/unsloth/DeepSeek-R1-Distill-Qwen-1.5B).