dineth554 commited on
Commit
73fb0f9
Β·
verified Β·
1 Parent(s): 0e67eb7

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +192 -126
README.md CHANGED
@@ -1,175 +1,241 @@
1
  ---
 
 
 
 
 
 
2
  language:
3
  - en
4
- tags:
5
  - code
6
- - coding
7
- - python
8
- - programming
 
9
  - text-generation
10
- - causal-lm
11
- - transformer
12
- - gpt
13
- - legion-coder
14
  - code-generation
15
- - code-completion
16
- license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  datasets:
18
  - the-stack-v2
19
- - codeparrot/github-code
20
- - bigcode/the-stack
 
 
 
21
  model-index:
22
  - name: Legion Coder 8M
23
  results: []
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  ---
25
 
26
- # Legion Coder 8M
27
 
28
- A compact yet powerful 44M parameter transformer model optimized for coding tasks. Legion Coder is designed to generate clean, efficient, and well-documented code while maintaining a small footprint suitable for local deployment.
29
 
30
- ## Model Details
 
31
 
32
- - **Architecture**: GPT-style transformer with pre-normalization
33
- - **Parameters**: 44,341,632 (~44M)
34
- - **Vocabulary Size**: 16,000 (BPE tokenizer optimized for code)
35
- - **Hidden Size (d_model)**: 576
36
- - **Layers**: 13
37
- - **Attention Heads**: 16
38
- - **Feed-forward Dimension**: 1,152
39
- - **Context Length**: 1,024 tokens
40
- - **Format**: Safetensors
41
- - **Precision**: float32
42
 
43
- ## Model Specifications
44
 
45
- | Attribute | Value |
46
- |-----------|-------|
47
- | Model Type | Causal Language Model |
48
- | Architecture | Transformer Decoder |
49
- | Parameters | 44,341,632 |
50
- | Hidden Size | 576 |
51
- | Num Layers | 13 |
52
- | Num Attention Heads | 16 |
53
- | Intermediate Size | 1,152 |
54
- | Max Position Embeddings | 1,024 |
55
- | Vocab Size | 16,000 |
56
 
57
- ## Intended Use
 
 
58
 
59
- This model is designed for:
60
- - **Code Generation**: Generate Python and other programming language code
61
- - **Code Completion**: Complete partial code snippets
62
- - **Code Explanation**: Provide explanations for code functionality
63
- - **Debugging Assistance**: Help identify and fix code issues
64
- - **Educational Purposes**: Learn programming concepts through examples
65
 
66
- ## Usage
 
 
 
 
67
 
68
- ### Loading the Model
69
 
70
- ```python
71
- from transformers import AutoModel, AutoTokenizer
72
- import torch
73
 
74
- # Load model and tokenizer
75
- model = AutoModel.from_pretrained("pnny13/legion-coder-8m", trust_remote_code=True)
76
- tokenizer = AutoTokenizer.from_pretrained("pnny13/legion-coder-8m", trust_remote_code=True)
77
 
78
- # Set to eval mode
79
- model.eval()
80
- ```
81
 
82
- ### Generating Code
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  ```python
85
- # Prepare prompt
86
- prompt = "# Write a function to calculate factorial\ndef factorial(n):"
87
- inputs = tokenizer(prompt, return_tensors="pt")
88
-
89
- # Generate
90
- with torch.no_grad():
91
- outputs = model.generate(
92
- inputs.input_ids,
93
- max_length=200,
94
- temperature=0.8,
95
- top_p=0.95,
96
- top_k=50
97
- )
98
-
99
- # Decode
100
- generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
101
- print(generated_code)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  ```
103
 
104
- ## System Prompt
 
 
105
 
106
- For optimal results, use the following system prompt:
107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  ```
109
- You are Legion Coder, an expert coding assistant. Your purpose is to help users write clean, efficient, and well-documented code.
110
 
111
- Guidelines:
112
- - Write code that follows best practices and PEP 8 style guidelines
113
- - Include helpful comments explaining complex logic
114
- - Provide complete, runnable code examples
115
- - Explain your approach before showing code when helpful
116
- - If asked to debug, identify the issue and provide the corrected code
117
 
118
- Always wrap code blocks in triple backticks with the appropriate language identifier.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  ```
120
 
121
- ## Training Details
122
 
123
  ### Training Data
124
  - Python code from The Stack v2 dataset
125
  - GitHub code repositories (filtered for quality)
126
- - Code-specific preprocessing to handle indentation and special tokens
127
 
128
  ### Training Procedure
129
- - Optimizer: AdamW
130
- - Learning Rate: 5e-4 with cosine decay
131
- - Batch Size: 4 with gradient accumulation
132
- - Training Steps: 10,000
133
- - Mixed Precision: No (CPU-optimized)
134
-
135
- ## Limitations
136
-
137
- - **Context Length**: Limited to 1,024 tokens
138
- - **Language Support**: Primarily optimized for Python
139
- - **Model Size**: 44M parameters may not capture all programming patterns
140
- - **Training Data**: May reflect biases present in training code
141
- - **No Internet Access**: Cannot access external APIs or documentation
142
-
143
- ## Ethical Considerations
144
-
145
- - Generated code should be reviewed before production use
146
- - The model may reproduce patterns from training data; verify licensing
147
- - Do not use for generating malicious code
148
- - Consider environmental impact of model inference
149
-
150
- ## Citation
151
-
152
- If you use this model in your research, please cite:
153
-
154
- ```bibtex
155
- @misc{legioncoder2024,
156
- title={Legion Coder 8M: A Compact Transformer for Code Generation},
157
- author={Legion Coder Team},
158
- year={2024},
159
- howpublished={\url{https://huggingface.co/pnny13/legion-coder-8m}}
160
- }
161
- ```
162
 
163
- ## License
164
 
165
- This model is released under the MIT License.
166
 
167
- ## Contact
168
 
169
- For questions or issues, please open an issue on the Hugging Face model repository.
 
170
 
171
- ---
 
 
 
 
 
 
172
 
173
- **Model Version**: 1.0.0
174
- **Last Updated**: 2024-03-08
175
- **Hugging Face Hub**: https://huggingface.co/pnny13/legion-coder-8m
 
1
  ---
2
+ # Model Card for Legion Coder 8M
3
+ # YAML Front Matter for Hugging Face Hub
4
+ base_model: dineth554/legion-coder-8m
5
+ library_name: transformers
6
+ license: mit
7
+ pipeline_tag: text-generation
8
  language:
9
  - en
 
10
  - code
11
+ tags:
12
+ - transformers
13
+ - pytorch
14
+ - safetensors
15
  - text-generation
 
 
 
 
16
  - code-generation
17
+ - python
18
+ - javascript
19
+ - coding
20
+ - programming
21
+ - sagemaker
22
+ - amazon-sagemaker
23
+ - cpu
24
+ - compact
25
+ - efficient
26
+ - nvdya-kit
27
+ - death-legion
28
+ - vllm
29
+ - sglang
30
+ - llama.cpp
31
+ - ollama
32
+ - lm-studio
33
+
34
  datasets:
35
  - the-stack-v2
36
+
37
+ metrics:
38
+ - perplexity
39
+ - accuracy
40
+
41
  model-index:
42
  - name: Legion Coder 8M
43
  results: []
44
+
45
+ inference:
46
+ parameters:
47
+ temperature: 0.8
48
+ top_p: 0.95
49
+ top_k: 50
50
+ max_new_tokens: 200
51
+
52
+ sagemaker:
53
+ sdk_version: "2.200.0"
54
+ instance_type: "ml.m5.large"
55
+ instance_count: 1
56
+ container_image: "huggingface-pytorch-inference:2.0.0-transformers4.28.1-cpu-py310-ubuntu20.04-v1.0"
57
  ---
58
 
59
+ # ⚑ Legion Coder 8M
60
 
61
+ **A 44M Parameter Transformer for Code Generation**
62
 
63
+ [![Made with by DEATH LEGION](https://img.shields.io/badge/MADE%20WITH%20BY-DEATH%20LEGION-ff0040?style=for-the-badge)](https://huggingface.co/dineth554/legion-coder-8m)
64
+ [![Powered by nvdya-kit](https://img.shields.io/badge/POWERED%20BY-nvdya--kit-7c4dff?style=for-the-badge)]()
65
 
66
+ ## πŸš€ Quick Links
 
 
 
 
 
 
 
 
 
67
 
68
+ <div align="center">
69
 
70
+ ### Libraries & Frameworks
 
 
 
 
 
 
 
 
 
 
71
 
72
+ [![Transformers](https://img.shields.io/badge/πŸ€—%20Transformers-Compatible-brightgreen?style=flat-square)](https://huggingface.co/docs/transformers)
73
+ [![PyTorch](https://img.shields.io/badge/PyTorch-2.1+-ee4c2c?style=flat-square&logo=pytorch)](https://pytorch.org/)
74
+ [![Safetensors](https://img.shields.io/badge/Safetensors-Format-blue?style=flat-square)](https://github.com/huggingface/safetensors)
75
 
76
+ ### Local Apps & Inference Engines
 
 
 
 
 
77
 
78
+ [![vLLM](https://img.shields.io/badge/vLLM-Supported-ff6b6b?style=flat-square)](https://docs.vllm.ai/)
79
+ [![SGLang](https://img.shields.io/badge/SGLang-New!-4ecdc4?style=flat-square)](https://sgl-project.github.io/)
80
+ [![llama.cpp](https://img.shields.io/badge/llama.cpp-Compatible-8b5cf6?style=flat-square)](https://github.com/ggerganov/llama.cpp)
81
+ [![Ollama](https://img.shields.io/badge/Ollama-Ready-f97316?style=flat-square)](https://ollama.ai/)
82
+ [![LM Studio](https://img.shields.io/badge/LM%20Studio-Compatible-10b981?style=flat-square)](https://lmstudio.ai/)
83
 
84
+ ### Notebooks & Cloud
85
 
86
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/dineth554/legion-coder-8m/blob/main/notebooks/legion_coder_demo.ipynb)
87
+ [![Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://kaggle.com/kernels/welcome?src=https://github.com/dineth554/legion-coder-8m/blob/main/notebooks/legion_coder_demo.ipynb)
 
88
 
89
+ </div>
 
 
90
 
91
+ ## πŸš€ About
92
+
93
+ Legion Coder is a compact yet powerful 44M parameter transformer model optimized for coding tasks. Built with precision by **DEATH LEGION** and powered by **nvdya-kit**, this model delivers high-quality code generation in a lightweight package.
94
 
95
+ ## ✨ Features
96
+
97
+ - πŸ“ **Clean Code Generation** - PEP 8 compliant Python and more
98
+ - πŸ› **Debug Assistance** - Help identify and fix code issues
99
+ - πŸ“š **Code Explanation** - Understand complex programming concepts
100
+ - πŸ’‘ **Multi-language Support** - Python, JavaScript, and more
101
+ - ⚑ **Fast Inference** - Optimized for CPU deployment
102
+ - ☁️ **SageMaker Ready** - One-click AWS deployment
103
+ - 🎯 **Template Ready** - Duplicate this space to create your own!
104
+
105
+ ## πŸ“Š Model Specifications
106
+
107
+ | Attribute | Value |
108
+ |-----------|-------|
109
+ | **Parameters** | 44,341,632 (~44M) |
110
+ | **Model Size** | ~170MB |
111
+ | **Architecture** | GPT-style Transformer |
112
+ | **Hidden Size** | 576 |
113
+ | **Layers** | 13 |
114
+ | **Attention Heads** | 16 |
115
+ | **Context Length** | 1,024 tokens |
116
+ | **Vocabulary** | 16,000 tokens |
117
+ | **Format** | Safetensors |
118
+
119
+ ## πŸš€ Amazon SageMaker Deployment
120
+
121
+ This model is ready for deployment on Amazon SageMaker with one-click deployment support.
122
+
123
+ ### ☁️ Deploy to AWS SageMaker
124
+
125
+ [![Deploy to SageMaker](https://img.shields.io/badge/πŸš€%20Deploy%20to-AWS%20SageMaker-FF9900?style=for-the-badge&logo=amazon-aws)](https://huggingface.co/dineth554/legion-coder-8m/deploy/sagemaker)
126
+
127
+ ### Using the SageMaker Python SDK
128
 
129
  ```python
130
+ import sagemaker
131
+ from sagemaker.huggingface import HuggingFaceModel
132
+
133
+ # Initialize SageMaker session
134
+ sess = sagemaker.Session()
135
+
136
+ # Create Hugging Face Model
137
+ huggingface_model = HuggingFaceModel(
138
+ model_data="dineth554/legion-coder-8m",
139
+ transformers_version="4.36.0",
140
+ pytorch_version="2.1.0",
141
+ py_version="py310",
142
+ role="arn:aws:iam::YOUR_ACCOUNT_ID:role/YOUR_SAGEMAKER_ROLE",
143
+ sagemaker_session=sess,
144
+ )
145
+
146
+ # Deploy to SageMaker
147
+ predictor = huggingface_model.deploy(
148
+ initial_instance_count=1,
149
+ instance_type="ml.m5.large",
150
+ endpoint_name="legion-coder-8m-endpoint"
151
+ )
152
+
153
+ # Test the endpoint
154
+ result = predictor.predict({
155
+ "inputs": "Write a Python function to calculate fibonacci numbers:",
156
+ "parameters": {
157
+ "temperature": 0.8,
158
+ "max_new_tokens": 200
159
+ }
160
+ })
161
+
162
+ print(result)
163
  ```
164
 
165
+ ### SageMaker Inference Script
166
+
167
+ The `sagemaker_inference.py` file in this repository provides the inference handler for SageMaker deployment.
168
 
169
+ ## πŸ› οΈ Local Inference with vLLM
170
 
171
+ ```python
172
+ from vllm import LLM, SamplingParams
173
+
174
+ # Load model with vLLM
175
+ llm = LLM(model="dineth554/legion-coder-8m")
176
+
177
+ # Set sampling parameters
178
+ sampling_params = SamplingParams(
179
+ temperature=0.8,
180
+ top_p=0.95,
181
+ max_tokens=200
182
+ )
183
+
184
+ # Generate code
185
+ prompt = "Write a Python function to calculate fibonacci numbers:"
186
+ outputs = llm.generate(prompt, sampling_params)
187
+ print(outputs[0].outputs[0].text)
188
  ```
 
189
 
190
+ ## πŸ› οΈ Local Inference with SGLang
 
 
 
 
 
191
 
192
+ ```python
193
+ import sglang as sgl
194
+
195
+ # Define prompt template
196
+ @sgl.function
197
+ def code_gen(s, prompt):
198
+ s += sgl.system("You are a helpful coding assistant.")
199
+ s += sgl.user(prompt)
200
+ s += sgl.assistant(sgl.gen("code", max_tokens=200))
201
+
202
+ # Run inference
203
+ result = code_gen.run(
204
+ prompt="Write a Python function to calculate fibonacci numbers:",
205
+ temperature=0.8
206
+ )
207
+ print(result["code"])
208
  ```
209
 
210
+ ## πŸ› οΈ Technical Details
211
 
212
  ### Training Data
213
  - Python code from The Stack v2 dataset
214
  - GitHub code repositories (filtered for quality)
215
+ - Code-specific preprocessing for indentation and special tokens
216
 
217
  ### Training Procedure
218
+ - **Optimizer:** AdamW
219
+ - **Learning Rate:** 5e-4 with cosine decay
220
+ - **Batch Size:** 4 with gradient accumulation
221
+ - **Training Steps:** 10,000
222
+ - **Precision:** float32 (CPU-optimized)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
 
224
+ ## πŸ“ License
225
 
226
+ This model is released under the **MIT License**.
227
 
228
+ ## πŸ”— Links
229
 
230
+ - **Model Repository:** [dineth554/legion-coder-8m](https://huggingface.co/dineth554/legion-coder-8m)
231
+ - **Live Demo:** [Hugging Face Space](https://huggingface.co/spaces/dineth554/legion-coder-8m)
232
 
233
+ <div align="center">
234
+
235
+ ### πŸ”₯ MADE WITH BY DEATH LEGION πŸ”₯
236
+
237
+ **Powered by nvdya-kit**
238
+
239
+ *Β© 2024 DEATH LEGION. All rights reserved.*
240
 
241
+ </div>