Instructions to use codeparrot/codeparrot-small-multi with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use codeparrot/codeparrot-small-multi with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="codeparrot/codeparrot-small-multi")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("codeparrot/codeparrot-small-multi") model = AutoModelForCausalLM.from_pretrained("codeparrot/codeparrot-small-multi") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use codeparrot/codeparrot-small-multi with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "codeparrot/codeparrot-small-multi" # 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-small-multi", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/codeparrot/codeparrot-small-multi
- SGLang
How to use codeparrot/codeparrot-small-multi 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-small-multi" \ --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-small-multi", "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-small-multi" \ --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-small-multi", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use codeparrot/codeparrot-small-multi with Docker Model Runner:
docker model run hf.co/codeparrot/codeparrot-small-multi
| language: | |
| - code | |
| license: apache-2.0 | |
| tags: | |
| - code | |
| - gpt2 | |
| - generation | |
| datasets: | |
| - "codeparrot/github-code-clean" | |
| - "openai_humaneval" | |
| metrics: | |
| - "evaluate-metric/code_eval" | |
| # CodeParrot-Multi 🦜 (small) | |
| CodeParrot-Multi 🦜 is a GPT-2 model (110M parameters) trained to generate code in 9 programming languages: "Java", "JavaScript", "PHP", "Python", "C#", "C++", "GO", "Ruby" and "TypeScript". | |
| ## Usage | |
| You can load the CodeParrot-Multi model and tokenizer directly in `transformers`: | |
| ```Python | |
| from transformers import AutoTokenizer, AutoModelWithLMHead | |
| tokenizer = AutoTokenizer.from_pretrained("codeparrot/codeparrot-small-multi") | |
| model = AutoModelWithLMHead.from_pretrained("codeparrot/codeparrot-small-multi") | |
| inputs = tokenizer("def hello_world():", return_tensors="pt") | |
| outputs = model(**inputs) | |
| ``` | |
| or with a `pipeline`: | |
| ```Python | |
| from transformers import pipeline | |
| pipe = pipeline("text-generation", model="codeparrot/codeparrot-small-multi") | |
| outputs = pipe("def hello_world():") | |
| ``` | |
| ## Training | |
| The model was trained on the small [Github code small](https://huggingface.co/datasets/loubnabnl/github-small-near-dedup) after near deduplication, a subset of [Github code dataset](https://huggingface.co/datasets/codeparrot/github-code-clean) with the following settings: | |
| |Config|Value| | |
| |-------|-----| | |
| |Batch size| 192 | | |
| |Context size| 1024 | | |
| |Training steps| 300'000| | |
| |Gradient accumulation| 2| | |
| |Gradient checkpointing| False| | |
| |Learning rate| 5e-4 | | |
| |Weight decay | 0.1 | | |
| |Warmup steps| 2000 | | |
| |Schedule| Cosine | | |
| The training was executed on 16 x A100 (40GB) GPUs. This setting amounts to roughly 58 billion tokens. | |
| ## Performance | |
| We evaluated the model on OpenAI's [HumanEval](https://huggingface.co/datasets/openai_humaneval) benchmark which consists of programming challenges: | |
| | Metric | Value | | |
| |-------|-----| | |
| |pass@1 | --% | | |
| |pass@10 | --% | | |
| |pass@100 | --% | | |
| The [pass@k metric](https://huggingface.co/metrics/code_eval) tells the probability that at least one out of k generations passes the tests. | |
| ## Resources | |
| - Code: [repository](https://github.com/huggingface/transformers/tree/master/examples/research_projects/codeparrot) | |