Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,175 +1,241 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
language:
|
| 3 |
- en
|
| 4 |
-
tags:
|
| 5 |
- code
|
| 6 |
-
|
| 7 |
-
-
|
| 8 |
-
-
|
|
|
|
| 9 |
- text-generation
|
| 10 |
-
- causal-lm
|
| 11 |
-
- transformer
|
| 12 |
-
- gpt
|
| 13 |
-
- legion-coder
|
| 14 |
- code-generation
|
| 15 |
-
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
datasets:
|
| 18 |
- the-stack-v2
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
model-index:
|
| 22 |
- name: Legion Coder 8M
|
| 23 |
results: []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
---
|
| 25 |
|
| 26 |
-
# Legion Coder 8M
|
| 27 |
|
| 28 |
-
A
|
| 29 |
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
-
|
| 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 |
-
|
| 44 |
|
| 45 |
-
|
| 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 |
-
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
###
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
import torch
|
| 73 |
|
| 74 |
-
|
| 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 |
-
#
|
| 79 |
-
|
| 80 |
-
|
| 81 |
|
| 82 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
```python
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
```
|
| 103 |
|
| 104 |
-
##
|
|
|
|
|
|
|
| 105 |
|
| 106 |
-
|
| 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 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
```
|
| 120 |
|
| 121 |
-
##
|
| 122 |
|
| 123 |
### Training Data
|
| 124 |
- Python code from The Stack v2 dataset
|
| 125 |
- GitHub code repositories (filtered for quality)
|
| 126 |
-
- Code-specific preprocessing
|
| 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 |
-
-
|
| 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 |
-
##
|
| 168 |
|
| 169 |
-
|
|
|
|
| 170 |
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
-
|
| 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 |
+
[](https://huggingface.co/dineth554/legion-coder-8m)
|
| 64 |
+
[]()
|
| 65 |
|
| 66 |
+
## π Quick Links
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
<div align="center">
|
| 69 |
|
| 70 |
+
### Libraries & Frameworks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
+
[](https://huggingface.co/docs/transformers)
|
| 73 |
+
[](https://pytorch.org/)
|
| 74 |
+
[](https://github.com/huggingface/safetensors)
|
| 75 |
|
| 76 |
+
### Local Apps & Inference Engines
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
+
[](https://docs.vllm.ai/)
|
| 79 |
+
[](https://sgl-project.github.io/)
|
| 80 |
+
[](https://github.com/ggerganov/llama.cpp)
|
| 81 |
+
[](https://ollama.ai/)
|
| 82 |
+
[](https://lmstudio.ai/)
|
| 83 |
|
| 84 |
+
### Notebooks & Cloud
|
| 85 |
|
| 86 |
+
[](https://colab.research.google.com/github/dineth554/legion-coder-8m/blob/main/notebooks/legion_coder_demo.ipynb)
|
| 87 |
+
[](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 |
+
[](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>
|
|
|
|
|
|