stas122 commited on
Commit
feed67b
·
verified ·
1 Parent(s): c7b8451

Upload 7 files

Browse files
chat_template.jinja ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if messages[0]["role"] == "system" %}
2
+ {%- set system_message = messages[0]["content"] %}
3
+ {%- set loop_messages = messages[1:] %}
4
+ {%- else %}
5
+ {%- set loop_messages = messages %}
6
+ {%- endif %}
7
+ {%- if not tools is defined %}
8
+ {%- set tools = none %}
9
+ {%- endif %}
10
+ {%- set user_messages = loop_messages | selectattr("role", "equalto", "user") | list %}
11
+
12
+ {#- This block checks for alternating user/assistant messages, skipping tool calling messages #}
13
+ {%- set ns = namespace() %}
14
+ {%- set ns.index = 0 %}
15
+ {%- for message in loop_messages %}
16
+ {%- if not (message.role == "tool" or message.role == "tool_results" or (message.tool_calls is defined and message.tool_calls is not none)) %}
17
+ {%- if (message["role"] == "user") != (ns.index % 2 == 0) %}
18
+ {{- raise_exception("After the optional system message, conversation roles must alternate user/assistant/user/assistant/...") }}
19
+ {%- endif %}
20
+ {%- set ns.index = ns.index + 1 %}
21
+ {%- endif %}
22
+ {%- endfor %}
23
+
24
+ {{- bos_token }}
25
+ {%- for message in loop_messages %}
26
+ {%- if message["role"] == "user" %}
27
+ {%- if tools is not none and (message == user_messages[-1]) %}
28
+ {{- "[AVAILABLE_TOOLS] [" }}
29
+ {%- for tool in tools %}
30
+ {%- set tool = tool.function %}
31
+ {{- '{"type": "function", "function": {' }}
32
+ {%- for key, val in tool.items() if key != "return" %}
33
+ {%- if val is string %}
34
+ {{- '"' + key + '": "' + val + '"' }}
35
+ {%- else %}
36
+ {{- '"' + key + '": ' + val|tojson }}
37
+ {%- endif %}
38
+ {%- if not loop.last %}
39
+ {{- ", " }}
40
+ {%- endif %}
41
+ {%- endfor %}
42
+ {{- "}}" }}
43
+ {%- if not loop.last %}
44
+ {{- ", " }}
45
+ {%- else %}
46
+ {{- "]" }}
47
+ {%- endif %}
48
+ {%- endfor %}
49
+ {{- "[/AVAILABLE_TOOLS]" }}
50
+ {%- endif %}
51
+ {%- if loop.last and system_message is defined %}
52
+ {{- "[INST] " + system_message + "\n\n" + message["content"] + "[/INST]" }}
53
+ {%- else %}
54
+ {{- "[INST] " + message["content"] + "[/INST]" }}
55
+ {%- endif %}
56
+ {%- elif message.tool_calls is defined and message.tool_calls is not none %}
57
+ {{- "[TOOL_CALLS] [" }}
58
+ {%- for tool_call in message.tool_calls %}
59
+ {%- set out = tool_call.function|tojson %}
60
+ {{- out[:-1] }}
61
+ {%- if not tool_call.id is defined or tool_call.id|length != 9 %}
62
+ {{- raise_exception("Tool call IDs should be alphanumeric strings with length 9!") }}
63
+ {%- endif %}
64
+ {{- ', "id": "' + tool_call.id + '"}' }}
65
+ {%- if not loop.last %}
66
+ {{- ", " }}
67
+ {%- else %}
68
+ {{- "]" + eos_token }}
69
+ {%- endif %}
70
+ {%- endfor %}
71
+ {%- elif message["role"] == "assistant" %}
72
+ {{- " " + message["content"]|trim + eos_token}}
73
+ {%- elif message["role"] == "tool_results" or message["role"] == "tool" %}
74
+ {%- if message.content is defined and message.content.content is defined %}
75
+ {%- set content = message.content.content %}
76
+ {%- else %}
77
+ {%- set content = message.content %}
78
+ {%- endif %}
79
+ {{- '[TOOL_RESULTS] {"content": ' + content|string + ", " }}
80
+ {%- if not message.tool_call_id is defined or message.tool_call_id|length != 9 %}
81
+ {{- raise_exception("Tool call IDs should be alphanumeric strings with length 9!") }}
82
+ {%- endif %}
83
+ {{- '"call_id": "' + message.tool_call_id + '"}[/TOOL_RESULTS]' }}
84
+ {%- else %}
85
+ {{- raise_exception("Only user and assistant roles are supported, with the exception of an initial optional system message!") }}
86
+ {%- endif %}
87
+ {%- endfor %}
config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "LlamaForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 1,
8
+ "dtype": "float32",
9
+ "eos_token_id": 2,
10
+ "head_dim": 64,
11
+ "hidden_act": "silu",
12
+ "hidden_size": 256,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 1024,
15
+ "max_position_embeddings": 512,
16
+ "mlp_bias": false,
17
+ "model_type": "llama",
18
+ "num_attention_heads": 4,
19
+ "num_hidden_layers": 21,
20
+ "num_key_value_heads": 4,
21
+ "pad_token_id": 2,
22
+ "pretraining_tp": 1,
23
+ "rms_norm_eps": 1e-05,
24
+ "rope_parameters": {
25
+ "rope_theta": 10000.0,
26
+ "rope_type": "default"
27
+ },
28
+ "tie_word_embeddings": true,
29
+ "transformers_version": "5.2.0",
30
+ "use_cache": false,
31
+ "vocab_size": 32768
32
+ }
generation_config.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": [
5
+ 2
6
+ ],
7
+ "output_attentions": false,
8
+ "output_hidden_states": false,
9
+ "pad_token_id": 2,
10
+ "transformers_version": "5.2.0",
11
+ "use_cache": true
12
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b517d4a950a083dfac9aa1d16f3c05103b3b00a83f926ee6f8d2fc2dbb717293
3
+ size 121699864
readme.md ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ **Model Card: Stentor Python 30M**
2
+
3
+ **Model Description**
4
+
5
+ Stentor Python 30M is a compact language model specifically fine-tuned for Python code generation and autocompletion tasks. Based on the Stentor-30M architecture, this model contains 30 million parameters and is designed to run efficiently on resource-constrained devices including mobile phones and embedded systems.
6
+
7
+ **Model Details**
8
+
9
+ - **Developed by:** Experimental fine-tuning project
10
+ - **Model type:** Causal language model (LlamaForCausalLM)
11
+ - **Language:** Python code, English instructions
12
+ - **Parameters:** 30,419,712
13
+ - **Context length:** 512 tokens
14
+ - **Model size:** 60 MB (FP16), 30 MB (INT8)
15
+ - **License:** Apache 2.0
16
+
17
+ **Training Data**
18
+
19
+ The model was fine-tuned on a curated dataset of 872 Python examples, including:
20
+
21
+ - Basic algorithms (factorial, prime numbers, list operations)
22
+ - Class implementations (Stack, BankAccount, Rectangle, Circle)
23
+ - Recursive functions (quicksort, Fibonacci)
24
+ - String manipulation (palindrome, anagram, vowel counting)
25
+ - MBPP (Mostly Basic Python Problems) dataset tasks
26
+
27
+ All examples follow a consistent format with "### Task:" instruction and "### Solution:" code block.
28
+
29
+ **Training Process**
30
+
31
+ The fine-tuning process involved multiple stages:
32
+
33
+ 1. Base model: Stentor-30M pre-trained checkpoint
34
+ 2. Initial fine-tuning on 50k examples (checkpoint-1000 selected as best)
35
+ 3. Multiple correction rounds with progressively lower learning rates
36
+ 4. Final detoxification training with learning rate 3e-7 to remove undesirable patterns
37
+
38
+ **Evaluation Results**
39
+
40
+ The model was evaluated on several test categories:
41
+
42
+ | Category | Pass Rate | Notes |
43
+ |----------|-----------|-------|
44
+ | Basic functions | 80% | Factorial, prime check, etc. |
45
+ | Classes from training set | 100% | Stack, BankAccount, Rectangle |
46
+ | New complex classes | 33% | Graph, Queue, inheritance |
47
+ | Function signatures (MBPP) | 100% | Correctly generates def statements |
48
+
49
+ **Capabilities**
50
+
51
+ - Generates Python functions from natural language descriptions
52
+ - Implements basic algorithms (factorial, prime check, palindrome)
53
+ - Creates class definitions with methods (Stack, BankAccount, Rectangle)
54
+ - Handles recursive functions (quicksort, Fibonacci)
55
+ - Produces syntactically correct function signatures
56
+
57
+ **Limitations**
58
+
59
+ - May produce repeated or redundant code after the main solution
60
+ - Struggles with complex data structures (graphs, trees, queues)
61
+ - Does not reliably handle class inheritance patterns
62
+ - Can generate incorrect list indexing operations
63
+ - May continue generating text beyond the intended solution
64
+ - Limited to 512 token context window
65
+ - Not suitable for production use without output post-processing
66
+
67
+ **Recommended Use Cases**
68
+
69
+ - Code autocompletion in lightweight IDEs
70
+ - Educational tool for Python beginners
71
+ - Rapid prototyping of simple functions
72
+ - Embedded systems with limited computational resources
73
+ - Offline code assistance on mobile devices
74
+
75
+ **Not Recommended For**
76
+
77
+ - Complex algorithm implementation
78
+ - Production code generation without human review
79
+ - Tasks requiring deep contextual understanding
80
+ - Generating large codebases
81
+ - Security-critical applications
82
+
83
+ **Usage Example**
84
+
85
+ ```python
86
+ from transformers import AutoTokenizer, AutoModelForCausalLM
87
+
88
+ model_path = "path/to/stentor-python-30m"
89
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
90
+ model = AutoModelForCausalLM.from_pretrained(model_path)
91
+
92
+ prompt = "### Task: Write a function that checks if a number is even\n\n### Solution:\n"
93
+ inputs = tokenizer(prompt, return_tensors="pt")
94
+ outputs = model.generate(**inputs, max_new_tokens=100, temperature=0.2)
95
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
96
+ ```
97
+
98
+ **Hardware Requirements**
99
+
100
+ - **Inference:** CPU only (no GPU required)
101
+ - **RAM:** < 100 MB for inference
102
+ - **Storage:** 60 MB (FP16), 30 MB (INT8 quantized)
103
+
104
+ **Ethical Considerations**
105
+
106
+ This model is intended for educational and development assistance purposes. Users should verify all generated code before deployment, particularly for security-sensitive applications. The model may occasionally produce incorrect or inefficient code and should not be relied upon as the sole source of truth for programming tasks.
107
+
108
+ **Citation**
109
+
110
+ If you use this model in your work, please cite:
111
+
112
+ ```
113
+ @misc{stentor-python-30m-2026,
114
+ author = {Fine-tuning Experiment},
115
+ title = {Stentor Python 30M: A Compact Model for Python Code Generation},
116
+ year = {2026},
117
+ publisher = {Hugging Face},
118
+ url = {https://huggingface.co/username/stentor-python-30m}
119
+ }
120
+ ```
121
+
122
+ **Contact**
123
+
124
+ For questions or feedback about this model, please open an issue on the Hugging Face repository.
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": true,
3
+ "backend": "tokenizers",
4
+ "bos_token": "<s>",
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "</s>",
7
+ "is_local": true,
8
+ "legacy": false,
9
+ "model_max_length": 512,
10
+ "pad_token": "</s>",
11
+ "sp_model_kwargs": {},
12
+ "spaces_between_special_tokens": false,
13
+ "tokenizer_class": "TokenizersBackend",
14
+ "unk_token": "<unk>",
15
+ "use_default_system_prompt": false
16
+ }