Llama 3.1 Future Code Ja is a large language model with 8B parameters built on top of the Meta Llama 3.1 model.
The model was first experienced continual pre-trained on the mixture of code and mostly-Japanese natural language data.
The training data is mainly from The Stack V2 dataset and the subset of LLM-jp Corpus v3, which comprises 204.9B code and 85.7B natural language tokens after carefully designed data cleaning.
The model was then merged with the instruct variant of the Meta Llama 3.1 model to acquire abilities to follow general task instructions, followed by supervised fine-tuning (SFT) and direct preference optimization (DPO) on our own magpie-generated code instruction data.
The model officially supports Japanese and English for natural languages and more than 40 programming languages ranging from popular Python, Java etc. to some legacy languages such as COBOL.
In addition to causal (left-to-right) inference, the model supports Fill-in-the-Middle (FIM) capability, where the model fills in the blank attending to bidirectional context, a common use case in IDEs.
The model outperforms the original Llama 3.1 model in both Japanese, and English-instructed code completion tasks in various programming languages, and outperforms Qwen families in Japanese generation tasks, attaining a good balance between specialty in code-related tasks and general ability in Japanese.
Usage
Here are the sample inference scripts with transformers.
We recommend using vLLM for faster inference.
pip install torch transformers accelerate
Chat
python
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
34model_name ="future-architect/Llama-3.1-Future-Code-Ja-8B"56model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")7tokenizer = AutoTokenizer.from_pretrained(model_name)89# we recommend using the following system prompt:10# for Japanese completion : "あなたは様々なソフトウェア開発タスクをサポートするAIアシスタントです。"11# for English completion : "You are an AI assistant who support various software development tasks."1213message =[14{15"role":"system",16"content":"あなたは様々なソフトウェア開発タスクをサポートするAIアシスタントです。"17},18{19"role":"user",20"content":"PythonでFizzBuzzを書いてください。",21},22]2324input_ids = tokenizer.apply_chat_template(25 message, add_generation_prompt=True, return_tensors="pt", return_dict=True26).to(model.device)2728output = model.generate(**input_ids, max_new_tokens=1024)2930print(tokenizer.decode(output[0, input_ids["input_ids"].shape[1]:]))
Fill-in-the-Middle
With the idea that the users may not want line breaks just after their cursor positions, we did not create any middle splits that start with newline symbols (\n), but included them at the end of the prefix instead.This also holds true for the boundaries of suffix and middle splits, causing great sensitivity against which split to include newline symbols.Please remove one new line symbol (if exists) from the beginning of the suffix for improved performance.
You may set a larger repetition penalty to avoid nonsense generations with too many signs.
python
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
34FIM_PREFIX ="<|fim_prefix|>"5FIM_MIDDLE ="<|fim_middle|>"6FIM_SUFFIX ="<|fim_suffix|>"78model_name ="future-architect/Llama-3.1-Future-Code-Ja-8B"910model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")11tokenizer = AutoTokenizer.from_pretrained(model_name)1213# prepend <|begin_of_text|> to inform that this is the beginning of "the content" (not whole sequence with special tokens)14prefix ="<|begin_of_text|>def fizzbuzz(n"15suffix ="return n"1617# PSM mode (infilling)18input_txt = FIM_PREFIX + prefix + FIM_SUFFIX + suffix + FIM_MIDDLE
19# SPM mode (reverse infilling)20# input_txt = FIM_PREFIX + FIM_SUFFIX + suffix + FIM_MIDDLE + prefix2122# set add_special_tokens to False, so that the tokenizer does NOT add <|begin_of_text|> before special tokens23input_ids = tokenizer(input_txt, add_special_tokens=False, return_tensors="pt").to(model.device)2425output = model.generate(**input_ids, max_new_tokens=1024, temperature=0.2, top_p=0.95)2627print(tokenizer.decode(output[0, input_ids["input_ids"].shape[1]:]))
Note: We do not report scores for two programming languages (Julia and Racket), which we did not include in the training data. All the scores below are pass@1 with 10 trials.
Note: We do not report scores for two programming languages (Julia and Racket), which we did not include in the training data. All the scores below are pass@1 with 10 trials.
Note: The models with asterisk (*) do not support FIM. We used the SPM prompt in Gong et al., 2024 and truncated the generated output just before the point that matched the beginning of the provided suffix. The scores of Llama models on PSM mode are not reported here since we got almost 0 scores for all those settings. All the scores below are exact match (EM) with 1 trial.
model
size
PSM (py)
SPM (py)
PSM (js)
SPM (js)
PSM (java)
SPM (java)
Llama 3.1 Future Code Ja
8B
0.5216
0.5139
0.6018
0.6049
0.5517
0.5478
Qwen2.5-Coder
7B
0.5829
0.4084
0.6612
0.5597
0.6433
0.6180
Llama 3.1 8B *
8B
-
0.4468
-
0.3951
-
0.3506
Llama 3.1 70B *
70B
-
0.5964
-
0.5084
-
0.2910
Japanese tasks
JCommonSenseQA (Kurihara et al., 2022, Exact Match)
We adopted the settings below for decoding.
We mostly followed the recommendations however, we set max_new_tokens instead of max_tokens to avoid truncation while handling long input sequences.
Temperature: 0.2
Top-p: 0.95
Number of completions to generate: 10 (for completion tasks), 1 (for FIM tasks)
Maximum number of new tokens: 512
We followed the evaluation strategy adopted in the Swallow project for Japanese and English tasks.
More specifically, we used the llm-jp-eval toolkit for Japanese tasks and the Language Model Evaluation Harness toolkit for English (and some Japanese) tasks.
We adopted the default decoding strategy for all the tasks.
Risks and Limitations
The model is trained on general tasks related to software development, not on organization-specific, and/or non-standardized tasks.
We recommend further fine-tuning the model to make it work better with those tasks.
The model may produce incorrect output and all the suggestions from the model must be carefully examined before adopting in real-world applications.
Acknowledgements
The model is developed as part of the Generative AI Accelerator Challenge (GENIAC) project.
We thank great support from the New Energy and Industrial Technology Development Organization (NEDO) and the Ministry of Economy, Trade and Industry (METI) for financial support.