https://github.com/bigcode-project/starcoder

Home of StarCoder: fine-tuning & inference!

https://github.com/bigcode-project/starcoder

Science Score: 33.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
    1 of 8 committers (12.5%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.0%) to scientific vocabulary

Keywords from Contributors

transformer vlm cryptocurrency jax cryptography audio speech-recognition agent deepseek gemma
Last synced: 10 months ago · JSON representation

Repository

Home of StarCoder: fine-tuning & inference!

Basic Info
  • Host: GitHub
  • Owner: bigcode-project
  • License: apache-2.0
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 67.4 KB
Statistics
  • Stars: 7,415
  • Watchers: 71
  • Forks: 526
  • Open Issues: 101
  • Releases: 0
Created about 3 years ago · Last pushed over 2 years ago
Metadata Files
Readme License

README.md

💫 StarCoder

Paper | Model | Playground | VSCode | Chat

What is this about?

💫 StarCoder is a language model (LM) trained on source code and natural language text. Its training data incorporates more that 80 different programming languages as well as text extracted from GitHub issues and commits and from notebooks. This repository showcases how we get an overview of this LM's capabilities.

News

  • May 9, 2023: We've fine-tuned StarCoder to act as a helpful coding assistant 💬! Check out the chat/ directory for the training code and play with the model here.

Disclaimer

Before you can use the model go to hf.co/bigcode/starcoder and accept the agreement. And make sure you are logged into the Hugging Face hub with: bash huggingface-cli login

Table of Contents

  1. Quickstart
  2. Fine-tuning
  3. Evaluation
  4. Inference hardware requirements

Quickstart

StarCoder was trained on GitHub code, thus it can be used to perform code generation. More precisely, the model can complete the implementation of a function or infer the following characters in a line of code. This can be done with the help of the 🤗's transformers library.

Installation

First, we have to install all the libraries listed in requirements.txt bash pip install -r requirements.txt

Code generation

The code generation pipeline is as follows

```python from transformers import AutoModelForCausalLM, AutoTokenizer

checkpoint = "bigcode/starcoder" device = "cuda" # for GPU usage or "cpu" for CPU usage

tokenizer = AutoTokenizer.from_pretrained(checkpoint)

to save memory consider using fp16 or bf16 by specifying torch_dtype=torch.float16 for example

model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)

inputs = tokenizer.encode("def printhelloworld():", return_tensors="pt").to(device) outputs = model.generate(inputs)

cleanuptokenization_spaces=False prevents a tokenizer edge case which can result in spaces being removed around punctuation

print(tokenizer.decode(outputs[0], cleanuptokenization_spaces=False)) or python from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline checkpoint = "bigcode/starcoder"

model = AutoModelForCausalLM.frompretrained(checkpoint) tokenizer = AutoTokenizer.frompretrained(checkpoint)

pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, device=0) print( pipe("def hello():") ) ``` For hardware requirements, check the section Inference hardware requirements.

Text-generation-inference

bash docker run -p 8080:80 -v $PWD/data:/data -e HUGGING_FACE_HUB_TOKEN=<YOUR BIGCODE ENABLED TOKEN> -d ghcr.io/huggingface/text-generation-inference:latest --model-id bigcode/starcoder --max-total-tokens 8192 For more details, see here.

Fine-tuning

Here, we showcase how we can fine-tune this LM on a specific downstream task.

Step by step installation with conda

Create a new conda environment and activate it bash conda create -n env conda activate env Install the pytorch version compatible with your version of cuda here, for example the following command works with cuda 11.6 bash conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia Install transformers and peft bash conda install -c huggingface transformers pip install git+https://github.com/huggingface/peft.git Note that you can install the latest stable version of transformers by using

bash pip install git+https://github.com/huggingface/transformers

Install datasets, accelerate and huggingface_hub

bash conda install -c huggingface -c conda-forge datasets conda install -c conda-forge accelerate conda install -c conda-forge huggingface_hub

Finally, install bitsandbytes and wandb bash pip install bitsandbytes pip install wandb To get the full list of arguments with descriptions you can run the following command on any script: python scripts/some_script.py --help Before you run any of the scripts make sure you are logged in and can push to the hub: bash huggingface-cli login Make sure you are logged in wandb: bash wandb login Now that everything is done, you can clone the repository and get into the corresponding directory.

Datasets

💫 StarCoder can be fine-tuned to achieve multiple downstream tasks. Our interest here is to fine-tune StarCoder in order to make it follow instructions. Instruction fine-tuning has gained a lot of attention recently as it proposes a simple framework that teaches language models to align their outputs with human needs. That procedure requires the availability of quality instruction datasets, which contain multiple instruction - answer pairs. Unfortunately such datasets are not ubiquitous but thanks to Hugging Face 🤗's datasets library we can have access to some good proxies. To fine-tune cheaply and efficiently, we use Hugging Face 🤗's PEFT as well as Tim Dettmers' bitsandbytes.

Stack Exchange SE

Stack Exchange is a well-known network of Q&A websites on topics in diverse fields. It is a place where a user can ask a question and obtain answers from other users. Those answers are scored and ranked based on their quality. Stack exchange instruction is a dataset that was obtained by scrapping the site in order to build a collection of Q&A pairs. A language model can then be fine-tuned on that dataset to make it elicit strong and diverse question-answering skills.

To execute the fine-tuning script run the following command: bash python finetune/finetune.py \ --model_path="bigcode/starcoder"\ --dataset_name="ArmelR/stack-exchange-instruction"\ --subset="data/finetune"\ --split="train"\ --size_valid_set 10000\ --streaming\ --seq_length 2048\ --max_steps 1000\ --batch_size 1\ --input_column_name="question"\ --output_column_name="response"\ --gradient_accumulation_steps 16\ --learning_rate 1e-4\ --lr_scheduler_type="cosine"\ --num_warmup_steps 100\ --weight_decay 0.05\ --output_dir="./checkpoints" \ The size of the SE dataset is better manageable when using streaming. We also have to precise the split of the dataset that is used. For more details, check the dataset's page on 🤗. Similarly we can modify the command to account for the availability of GPUs

bash python -m torch.distributed.launch \ --nproc_per_node number_of_gpus finetune/finetune.py \ --model_path="bigcode/starcoder"\ --dataset_name="ArmelR/stack-exchange-instruction"\ --subset="data/finetune"\ --split="train"\ --size_valid_set 10000\ --streaming \ --seq_length 2048\ --max_steps 1000\ --batch_size 1\ --input_column_name="question"\ --output_column_name="response"\ --gradient_accumulation_steps 16\ --learning_rate 1e-4\ --lr_scheduler_type="cosine"\ --num_warmup_steps 100\ --weight_decay 0.05\ --output_dir="./checkpoints" \

Merging PEFT adapter layers

If you train a model with PEFT, you'll need to merge the adapter layers with the base model if you want to run inference / evaluation. To do so, run: ```bash python finetune/mergepeftadapters.py --basemodelnameorpath modeltomerge --peftmodelpath model_checkpoint

Push merged model to the Hub

python finetune/mergepeftadapters.py --basemodelnameorpath modeltomerge --peftmodelpath modelcheckpoint --pushto_hub ``` For example

bash python finetune/merge_peft_adapters.py --model_name_or_path bigcode/starcoder --peft_model_path checkpoints/checkpoint-1000 --push_to_hub

Evaluation

To evaluate StarCoder and its derivatives, you can use the BigCode-Evaluation-Harness for evaluating Code LLMs.

Inference hardware requirements

In FP32 the model requires more than 60GB of RAM, you can load it in FP16 or BF16 in ~30GB, or in 8bit under 20GB of RAM with ```python

make sure you have accelerate and bitsandbytes installed

from transformers import AutoModelForCausalLM, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("bigcode/starcoder")

for fp16 replace with load_in_8bit=True with torch_dtype=torch.float16

model = AutoModelForCausalLM.frompretrained("bigcode/starcoder", devicemap="auto", loadin8bit=True) print(f"Memory footprint: {model.getmemoryfootprint() / 1e6:.2f} MB") ` Memory footprint: 15939.61 MB ``` You can also try starcoder.cpp, a C++ implementation with ggml library.

Owner

  • Name: BigCode Project
  • Login: bigcode-project
  • Kind: organization
  • Email: contact@bigcode-project.org

BigCode Project is an open scientific collaboration run by Hugging Face and ServiceNow Research, focused on open and responsible development of LLMs for code.

GitHub Events

Total
  • Issues event: 2
  • Watch event: 243
  • Issue comment event: 2
  • Fork event: 31
Last Year
  • Issues event: 2
  • Watch event: 243
  • Issue comment event: 2
  • Fork event: 31

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 68
  • Total Committers: 8
  • Avg Commits per committer: 8.5
  • Development Distribution Score (DDS): 0.176
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
ArmelRandy 7****y 56
Loubna Ben Allal 4****l 4
lewtun l****l@g****m 2
Leandro von Werra l****a 2
Ikko Eltociear Ashimine e****r@g****m 1
Eryk Mazuś e****s@g****m 1
Daniel Fried d****d@a****u 1
Arjun Guha a****a 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 89
  • Total pull requests: 14
  • Average time to close issues: 13 days
  • Average time to close pull requests: 1 day
  • Total issue authors: 78
  • Total pull request authors: 11
  • Average comments per issue: 2.98
  • Average comments per pull request: 0.43
  • Merged pull requests: 8
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 3
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 3
  • Pull request authors: 0
  • Average comments per issue: 0.33
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • phalexo (3)
  • ruchaa0112 (3)
  • Kushalamummigatti (3)
  • GurpreetSingh97 (2)
  • avadhut123pisal (2)
  • umm-maybe (2)
  • edwardelric1202 (2)
  • h-clickshift (2)
  • drorbrillsnps (1)
  • wwwjwww (1)
  • astarostap (1)
  • Maomaoxion (1)
  • edward-io (1)
  • xpl (1)
  • danilbilous (1)
Pull Request Authors
  • arjunguha (2)
  • loubnabnl (2)
  • KINNNNNNG (1)
  • giprime (1)
  • nopperl (1)
  • dpfried (1)
  • lewtun (1)
  • eryk-mazus (1)
  • eltociear (1)
  • didier-durand (1)
  • MubarakHAlketbi (1)
Top Labels
Issue Labels
Pull Request Labels

Dependencies

requirements.txt pypi
  • accelerate ==0.18.0
  • datasets ==2.11.0
  • huggingface-hub ==0.13.4
  • tqdm ==4.65.0
  • transformers ==4.28.1
chat/requirements.txt pypi
  • accelerate >=0.18.0
  • datasets >=2.12.0
  • deepspeed ==0.9.1
  • tensorboard *
  • tokenizers >=0.13.3
  • transformers >=4.28.1