Text Generation
Transformers
Safetensors
PyTorch
English
gpt2
code-completion
huggingface
codexglue
nlp
machine-learning
Instructions to use Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE
- SGLang
How to use Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE with Docker Model Runner:
docker model run hf.co/Sai-Nandu/Code-Completion-using-GPT-2-CodeXGLUE
updated readme
Browse files
README.md
CHANGED
|
@@ -1,9 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GPT-2 Fine-Tuned for Python Code Completion
|
| 2 |
+
|
| 3 |
+
This repository contains a fine-tuned **GPT-2** model for **Python source code completion**. The model was trained on the **CodeXGLUE Python Code Completion** dataset using the Hugging Face Transformers library and PyTorch.
|
| 4 |
+
|
| 5 |
+
## Model Description
|
| 6 |
+
|
| 7 |
+
This model is designed to predict the next tokens in Python source code, enabling intelligent code completion for software development tasks.
|
| 8 |
+
|
| 9 |
+
- **Base Model:** GPT-2
|
| 10 |
+
- **Task:** Causal Language Modeling
|
| 11 |
+
- **Language:** Python
|
| 12 |
+
- **Framework:** PyTorch
|
| 13 |
+
- **Library:** Hugging Face Transformers
|
| 14 |
+
|
| 15 |
---
|
| 16 |
+
|
| 17 |
+
## Dataset
|
| 18 |
+
|
| 19 |
+
**Dataset:** CodeXGLUE – Python Code Completion
|
| 20 |
+
|
| 21 |
+
The dataset contains Python source code snippets used to train language models for next-token code prediction.
|
| 22 |
+
|
| 23 |
+
Note: A subset of approximately 13,000 training samples from the CodeXGLUE Python dataset was used for fine-tuning.
|
| 24 |
+
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
## Training Configuration
|
| 28 |
+
|
| 29 |
+
| Parameter | Value |
|
| 30 |
+
|-----------|--------|
|
| 31 |
+
| Model | GPT-2 |
|
| 32 |
+
| Epochs | 3 |
|
| 33 |
+
| Learning Rate | 2e-4 |
|
| 34 |
+
| Batch Size | 4 |
|
| 35 |
+
| Gradient Accumulation | 4 |
|
| 36 |
+
| Weight Decay | 0.01 |
|
| 37 |
+
| Max Sequence Length | 512 |
|
| 38 |
+
| Optimizer | AdamW |
|
| 39 |
+
| Framework | PyTorch |
|
| 40 |
+
|
| 41 |
+
Training was performed using the Hugging Face `Trainer` API.
|
| 42 |
+
|
| 43 |
+
---
|
| 44 |
+
|
| 45 |
+
## Evaluation Results
|
| 46 |
+
|
| 47 |
+
| Metric | Value |
|
| 48 |
+
|---------|---------|
|
| 49 |
+
| Validation Loss | **1.1869** |
|
| 50 |
+
| Perplexity | **3.28** |
|
| 51 |
+
|
| 52 |
+
The decreasing validation loss throughout training indicates successful adaptation of GPT-2 to the Python code completion task.
|
| 53 |
+
|
| 54 |
+
---
|
| 55 |
+
|
| 56 |
+
## Training Progress
|
| 57 |
+
|
| 58 |
+
| Step | Training Loss | Validation Loss |
|
| 59 |
+
|------|---------------|----------------|
|
| 60 |
+
|100|1.5613|1.3592|
|
| 61 |
+
|200|1.3962|1.2877|
|
| 62 |
+
|300|1.3317|1.2537|
|
| 63 |
+
|400|1.2437|1.2308|
|
| 64 |
+
|500|1.2253|1.2142|
|
| 65 |
+
|600|1.2014|1.2000|
|
| 66 |
+
|Final|—|**1.1869**|
|
| 67 |
+
|
| 68 |
+
---
|
| 69 |
+
|
| 70 |
+
## Usage
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 74 |
+
|
| 75 |
+
tokenizer = AutoTokenizer.from_pretrained("YOUR_USERNAME/MODEL_NAME")
|
| 76 |
+
model = AutoModelForCausalLM.from_pretrained("YOUR_USERNAME/MODEL_NAME")
|
| 77 |
+
|
| 78 |
+
prompt = "def fibonacci(n):"
|
| 79 |
+
|
| 80 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 81 |
+
|
| 82 |
+
outputs = model.generate(
|
| 83 |
+
**inputs,
|
| 84 |
+
max_new_tokens=50,
|
| 85 |
+
do_sample=True,
|
| 86 |
+
temperature=0.7
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
---
|
| 93 |
+
|
| 94 |
+
## Limitations
|
| 95 |
+
|
| 96 |
+
- Trained only on Python source code.
|
| 97 |
+
- Intended for research and educational purposes.
|
| 98 |
+
- May generate syntactically incorrect or incomplete code.
|
| 99 |
+
- Does not guarantee production-quality code suggestions.
|
| 100 |
+
|
| 101 |
+
---
|
| 102 |
+
|
| 103 |
+
## Technologies Used
|
| 104 |
+
|
| 105 |
+
- Python
|
| 106 |
+
- PyTorch
|
| 107 |
+
- Hugging Face Transformers
|
| 108 |
+
- Hugging Face Datasets
|
| 109 |
+
- CodeXGLUE Dataset
|
| 110 |
+
|
| 111 |
+
---
|
| 112 |
+
|
| 113 |
+
## Future Improvements
|
| 114 |
+
|
| 115 |
+
- Fine-tune larger transformer models.
|
| 116 |
+
- Train on larger subsets of CodeXGLUE.
|
| 117 |
+
- Evaluate using additional code generation metrics.
|
| 118 |
+
- Support multiple programming languages.
|
| 119 |
+
- Deploy as an inference API.
|
| 120 |
+
|
| 121 |
+
---
|
| 122 |
+
|
| 123 |
+
## Author
|
| 124 |
+
|
| 125 |
+
**Sai Nandu Vajhala**
|
| 126 |
+
|
| 127 |
+
GitHub: https://github.com/SaiNanduVajhala
|
| 128 |
+
|
| 129 |
+
LinkedIn: https://www.linkedin.com/in/sai-nandu-vajhala
|