Instructions to use codeparrot/codeparrot with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use codeparrot/codeparrot with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="codeparrot/codeparrot")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("codeparrot/codeparrot") model = AutoModelForCausalLM.from_pretrained("codeparrot/codeparrot") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use codeparrot/codeparrot with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "codeparrot/codeparrot" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "codeparrot/codeparrot", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/codeparrot/codeparrot
- SGLang
How to use codeparrot/codeparrot 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 "codeparrot/codeparrot" \ --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": "codeparrot/codeparrot", "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 "codeparrot/codeparrot" \ --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": "codeparrot/codeparrot", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use codeparrot/codeparrot with Docker Model Runner:
docker model run hf.co/codeparrot/codeparrot
CodeParrot π¦
CodeParrot π¦ is a GPT-2 model (1.5B parameters) trained to generate Python code. After the initial training and release of v1.0 we trained the model some more and released v1.1 (see below for details).
Usage
You can load the CodeParrot model and tokenizer directly in transformers:
from transformers import AutoTokenizer, AutoModelWithLMHead
tokenizer = AutoTokenizer.from_pretrained("codeparrot/codeparrot")
model = AutoModelWithLMHead.from_pretrained("codeparrot/codeparrot")
inputs = tokenizer("def hello_world():", return_tensors="pt")
outputs = model(**inputs)
or with a pipeline:
from transformers import pipeline
pipe = pipeline("text-generation", model="codeparrot/codeparrot")
outputs = pipe("def hello_world():")
Training
The model was trained on the cleaned CodeParrot π¦ dataset in two steps. After the initial training (v1.0) the model was trained for another 30k steps resulting in v1.1 and you find the settings in the following table:
| Config | v1.0 | v1.1 |
|---|---|---|
| Batch size | 512 | 512 |
| Context size | 1024 | 1024 |
| Training steps | 50'000 | 30'000 |
| Gradient accumulation | 16 | 16 |
| Gradient checkpointing | True | True |
| Learning rate | 2e-4 | 5e-5 |
| Weight decay | 0.1 | 0.1 |
| Warmup steps | 750 | 750 |
| Schedule | Cosine | Cosine |
The training was executed on 16 x A100 (40GB) GPUs. This setting amounts to roughly 26 + 15 billion tokens.
Performance
We evaluated the model on OpenAI's HumanEval benchmark which consists of programming challenges:
| Metric | v1.0 | v1.1 |
|---|---|---|
| pass@1 | 3.58% | 3.99% |
| pass@10 | 8.03% | 8.69% |
| pass@100 | 14.96% | 17.88% |
The pass@k metric tells the probability that at least one out of k generations passes the tests.
Resources
- Dataset: full, train, valid
- Code: repository
- Spaces: generation, highlighting
- Downloads last month
- 2,189
Model tree for codeparrot/codeparrot
Dataset used to train codeparrot/codeparrot
Spaces using codeparrot/codeparrot 19
Evaluation results
- pass@1 on HumanEvalself-reported3.990
- pass@10 on HumanEvalself-reported8.690
- pass@100 on HumanEvalself-reported17.880