Home

Awesome

<div align="center"> <img src="https://github.com/01-ai/Yi-Coder/blob/main/assets/coder-readme.gif?raw=true" alt="yicoder" width="400"/> </div> <div align="center"> <a href="https://github.com/01-ai">🐙 GitHub</a> • <a href="https://discord.gg/hYUwWddeAu">👾 Discord</a> • <a href="https://twitter.com/01ai_yi">🐤 Twitter</a> • <a href="https://github.com/01-ai/Yi-1.5/issues/2">💬 WeChat</a> • <a href="https://01-ai.github.io/blog.html?post=en/2024-09-05-A-Small-but-Mighty-LLM-for-Code.md">📑 Blog</a> </div>

Intro

Yi-Coder is a series of open-source code language models that delivers state-of-the-art coding performance with fewer than 10 billion parameters.

Key features:

  'java', 'markdown', 'python', 'php', 'javascript', 'c++', 'c#', 'c', 'typescript', 'html', 'go', 'java_server_pages', 'dart', 'objective-c', 'kotlin', 'tex', 'swift', 'ruby', 'sql', 'rust', 'css', 'yaml', 'matlab', 'lua', 'json', 'shell', 'visual_basic', 'scala', 'rmarkdown', 'pascal', 'fortran', 'haskell', 'assembly', 'perl', 'julia', 'cmake', 'groovy', 'ocaml', 'powershell', 'elixir', 'clojure', 'makefile', 'coffeescript', 'erlang', 'lisp', 'toml', 'batchfile', 'cobol', 'dockerfile', 'r', 'prolog', 'verilog'
NameTypeLengthDownload
Yi-Coder-9B-ChatChat128K🤗 Hugging Face🤖 ModelScope🟣 wisemodel
Yi-Coder-1.5B-ChatChat128K🤗 Hugging Face🤖 ModelScope🟣 wisemodel
Yi-Coder-9BBase128K🤗 Hugging Face🤖 ModelScope🟣 wisemodel
Yi-Coder-1.5BBase128K🤗 Hugging Face🤖 ModelScope🟣 wisemodel

For more details, see Yi-Coder blog

News

🔥 2024-09-05: The Yi-Coder series models are open sourced and available to the public.

Quick Start

Requirements

Make sure you have python>=3.9 installed before using it. To set up the environment and install the requirements, run the following command:

git clone https://github.com/01-ai/Yi-Coder.git
cd Yi-Coder
pip install -r requirements.txt

Ollama

You can run Yi-Coder on Ollama locally.

  1. After installing Ollama, you can start the Ollama service. Note that keep this service running while you use Ollama.

    ollama serve
    
  2. Run Yi-Coder models. For more Yi models supported by Ollama, see Yi tags.

    ollama run yi-coder
    

Transformers

You can use transformers to run inference with Yi-Coder models (both chat and base versions) as follows:

from transformers import AutoTokenizer, AutoModelForCausalLM

device = "cuda" # the device to load the model onto
model_path = "01-ai/Yi-Coder-9B-Chat"

tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto").eval()

prompt = "Write a quick sort algorithm."
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)

generated_ids = model.generate(
    model_inputs.input_ids,
    max_new_tokens=1024,
    eos_token_id=tokenizer.eos_token_id  
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)

vLLM

You can also use vLLM to reason about Yi-Coder models. vLLM is a fast and easy-to-use library for reasoning about and serving large language models (LLMs). Be sure to install vLLM and then do the following

from transformers import AutoTokenizer
from vllm import LLM, SamplingParams
model_path = "01-ai/Yi-Coder-9B-Chat"

tokenizer = AutoTokenizer.from_pretrained(model_path)

sampling_params = SamplingParams(
    temperature=0.8,
    top_p=0.8)

llm = LLM(model=model_path, 
          gpu_memory_utilization=0.9, 
          max_model_len=1024)

prompt = "Write a quick sort algorithm."  
messages = [
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
print(text)

# Generate the response
outputs = llm.generate([text], sampling_params)

# Print the output
for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

Cookbook

Results

For the highlight of full results, please refer to our blog post. Below we present more detailed results for multilingual HumanEval, CodeEditorBench, and math programming.

Multi-lingual HumanEval

  1. Base model comparison
ModelSizePythonC++JavaPHPTSC#BashJSAvg
CodeLLama34B48.244.744.941.042.148.715.842.241.0
StarCoder215B46.341.433.939.543.829.218.944.237.2
DeepSeek-Coder-Base1.3B34.831.132.324.228.936.710.128.628.3
DeepSeek-Coder-Base6.7B49.450.343.038.549.750.028.548.444.7
DeepSeek-Coder-Base33B56.158.451.944.152.851.332.355.350.3
CodeQwen1.57B52.452.242.446.652.255.736.749.748.5
Yi-Coder1.5B41.537.932.934.235.938.68.939.133.6
Yi-Coder9B53.759.636.745.357.958.230.454.749.6
  1. Instruction-tuned model comparison
ModelSizePythonC++JavaPHPTSC#BashJSAvg
GPT-484.176.481.677.277.479.158.278.076.5
DeepSeek-Coder-Instruct1.3B65.245.351.145.359.755.112.752.248.4
DeepSeek-Coder-Instruct6.7B78.963.468.468.967.272.836.772.766.1
DeepSeek-Coder-Instruct33B79.368.973.472.767.974.143.073.969.2
CodeQwen1.5-Chat7B83.271.270.173.575.475.941.178.271.1
Yi-Coder-Chat1.5B67.749.151.952.257.957.619.059.651.9
Yi-Coder-Chat9B85.467.776.072.172.376.645.678.971.8

CodeEditorBench

  1. Primary
ModelsDebugTranslationSwitchPolishAvg Win Rate
GPT-449.30%50.30%26.40%1.33%85.72%
Yi-Coder-9B-Chat46.09%42.60%14.06%7.04%78.57%
DS-Coder-33B-Instruct48.70%45.10%16.20%1.14%67.86%
CodeQwen1.5-7B-Chat42.37%34.20%11.37%5.03%57.14%
GLM-427.10%36.50%8.50%6.46%50.00%
CodeLLaMA-13B-Instruct36.80%27.50%2.10%1.82%39.29%
CodeLLaMA-7b-Instruct33.60%23.10%1.70%1.17%21.43%
  1. Plus
ModelsDebugTranslationSwitchPolishAvg Win Rate
GPT-431.60%46.50%26.40%1.12%82.14%
Yi-Coder-9B-Chat26.44%34.91%14.06%5.87%75.00%
DS-Coder-33B-Instruct27.50%41.00%16.20%1.10%67.86%
CodeQwen1.5-7B-Chat20.90%36.27%11.37%2.91%60.72%
GLM-422.00%27.80%8.50%5.17%50.00%
CodeLLaMA-13B-Instruct17.60%33.30%2.10%2.31%39.29%
CodeLLaMA-7b-Instruct15.50%28.90%1.70%1.47%25.00%

Math Programming

ModelSizeGSM8kMATHGSM-HardSVAMPTabMWPASDivMAWPSAvg
CodeShell7B15.88.617.335.528.244.459.829.9
CodeGeex-27B22.29.723.639.044.648.566.036.2
StarCoder-Base16B23.410.323.042.445.054.981.140.0
CodeLLama-Base7B31.212.130.254.252.959.682.646.1
CodeLLama-Base13B43.114.440.259.260.363.685.352.3
CodeLLama-Base34B58.221.251.870.369.870.791.862.0
DeepSeek-Coder-Base1.3B14.616.814.536.730.048.262.331.9
DeepSeek-Coder-Base6.7B43.219.240.358.467.967.287.054.7
DeepSeek-Coder-Base33B60.729.154.171.675.376.793.365.8
Yi-Coder1.5B25.511.427.742.436.259.375.539.7
Yi-Coder9B68.129.161.077.881.281.093.970.3

How to Reproduce Our Results

To ensure the fairness of our evaluation, we follow the official implementations to obtain the evaluation results for most of the benchmarks we considered, including LiveCodeBench, CRUXEval-O, CodeEditorBench, and CrossCodeEval. For HumanEval (zero-shot, multilingual), MBPP (3-shot), and 7 math programming tasks, we follow the widely adopted evaluation codebase released by DeepSeek-Coder.

License

The code and weights of the Yi-Coder series models are distributed under the Apache 2.0 license.

If you create derivative works based on this model, please include the following attribution in your derivative works:

This work is a derivative of [The Yi Series Model You Based On] by 01.AI, licensed under the Apache 2.0 License.