Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

CodeTF

> 数据库
Open source

CodeTF: One-stop Transformer Library for State-of-the-art Code LLM

1.5K stars0 likes1 views
WebsiteGitHub

About

CodeTF: One-stop Transformer Library for State-of-the-art Code LLM


<br>

Table of Contents

  • Introduction
  • Installation
  • Getting Started
    • Inferencing Pipeline
    • Model Zoo
    • Fine-Tuning Your Own Model
    • Evaluate On Well-Known Benchmarks
    • Utilities to Manipulate Source Code Based on AST
      • AST Parser in Multiple Languages
      • Extract Code Attributes
      • Remove Comments
  • Ethical and Responsible Use
  • License

Introduction

CodeTF is a one-stop Python transformer-based library for code large language models (Code LLMs) and code intelligence, provides a seamless interface for training and inferencing on code intelligence tasks like code summarization, translation, code generation and so on. It aims to facilitate easy integration of SOTA CodeLLMs into real-world applications.

In addition to the core LLMs's features for code, CodeTF offers utilities for code manipulation across various languages, including easy extraction of code attributes. Using tree-sitter as its core AST parser, it enables parsing of attributes such as function names, comments, and variable names. Pre-built libraries for numerous languages are provided, eliminating the need for complicated parser setup. CodeTF thus ensures a user-friendly and accessible environment for code intelligence tasks.

The current version of the library offers:

  • Fast Model Serving: We support an easy-to-use interface for rapid inferencing with pre-quantized models (int8, int16, float16). CodeTF handles all aspects of device management, so users do not have to worry about that aspect. If your model is large, we offer advanced features such as weight sharding across GPUs to serve the models more quickly.
  • Fine-Tuning Your Own Models: We provide an API for quickly fine-tuning your own LLMs for code using SOTA techniques for parameter-efficient fine-tuning (HuggingFace PEFT) on distributed environments.
  • Supported Tasks: nl2code, code summarization, code completion, code translation, code refinement, clone detection, defect prediction.
  • Datasets+: We have preprocessed well-known benchmarks (Human-Eval, MBPP, CodeXGLUE, APPS, etc.) and offer an easy-to-load feature for these datasets.
  • Model Evaluator: We provide interface to evaluate models on well-known benchmarks (e.g. Human-Eval) on popular metrics (e.g., pass@k) with little effort (~15 LOCs).
  • Pretrained Models: We supply pretrained checkpoints of state-of-the-art foundational language models of code (CodeBERT, CodeT5, CodeGen, CodeT5+, Incoder, StarCoder, etc.).
  • Fine-Tuned Models: We furnish fine-tuned checkpoints for 8+ downstream tasks.
  • Utility to Manipulate Source Code: We provide utilities to easily manipulate source code, such as user-friendly AST parsers (based on tree-sitter) in 15+ programming languages, to extract important code features, such as function name, identifiers, etc.

The following table shows the supported models with sizes and the tasks that the models support. This is a continuing effort and we are working on further growing the list.

Model Size Tasks
CodeT5 Base, Base-multi-sum, Base-translate-cs, Base-translate-java, Base-sum, Base-clone, Base-defect Pretrained, NL to Code, Refine, Translation (CS to Java, Java to CS), Summarization (Python, Go, PHP, JavaScript, Java, Ruby), Clone detection, Defect prediction
CodeT5+ Plus-instruct-16B, Plus-16B, Plus-6B, Plus-2B, Plus-770M-python, Plus-770M, Plus-220M Pretrained, NL to Code, Refine , Defect prediction
CodeGen Mono: 350M, 2B, 6B, 1B, 3.7B, 7B, 16B
Multi: 350M, 2B, 6B
NL: 350M, 2B
Pretrained
StarCoder 15.5B Pretrained
SantaCoder 1.1B Pretrained
GPT-NeoX 20B Pretrained
GPT-Neo 1.3B Pretrained
GPT-J 6B Pretrained
Incoder 6B Pretrained
CodeParrot Small-python (110M), Small-multi(110M), 1.5B Pretrained
CodeBERT CodeBERT-base, UnixCoder-base, CodeBERTa-small Pretrained

Installation Guide

  1. (Optional) Creating conda environment
bash
conda create -n codetf python=3.8
conda activate codetf
  1. Install from PyPI:
bash
pip install salesforce-codetf
  1. Alternatively, build CodeTF from source:
bash
git clone https://github.com/salesforce/CodeTF.git
cd CodeTF
pip install -e .

Additionally, to make sure the quantization feature works well, also install these dependencies:

bash
pip install -q -U git+https://github.com/huggingface/transformers.git
pip install -q -U git+https://github.com/huggingface/peft.git
pip install -q -U git+https://github.com/huggingface/accelerate.git

For some models, such as StarCoder, it is required to log in Huggingface. Please obtain the HuggingFace token and login:

huggingface-cli login

Getting Started

Inferencing Pipeline

Getting started with CodeTF is simple and quick with our model loading pipeline function load_model_pipeline(). Here's an example showing how to load codet5+ model and perform inference on code generation task:

python
from codetf.models import load_model_pipeline

code_generation_model = load_model_pipeline(model_name="codet5", task="pretrained",
            model_type="plus-770M-python", is_eval=True,
            load_in_8bit=True, load_in_4bit=False, weight_sharding=False)
            
result = code_generation_model.predict(["def print_hello_world():"])
print(result)

There are a few notable arguments that need to be considered:

  • model_name: the name of the model, currently support codet5 and causal-lm.
  • model_type: type of model for each model name, e.g. base, codegen-350M-mono, j-6B, etc.
  • load_in_8bit and load_in_4bit: inherit the dynamic quantization feature from Huggingface Quantization.
  • weight_sharding: our advance feature that leverages HuggingFace Sharded Checkpoint to split a large model in several smaller shards in different GPUs. Please consider using this if you are dealing with large models.

Model Zoo

You might want to view all of the supported models. To do this, you can use the model_zoo():

…

Fine-Tuning Pipeline

Want to train a custom LLM for code? We've got you covered. Below is an example using the Seq2SeqTrainer to fine-tune a CodeT5+ pretrained model, along with our dataset utilities, make it easy to fine-tune your models using the CodeXGLUE dataset. Here's an example:

…

Comparing to this script from StarCoder, which requires ~300 LOCs to fine-tune a model, we only need 14 LOCs to do the same !!!

Evaluate on Well-Known Benchmarks

Planning to reproduce the results of well-known benchmarks like Human-Eval, but struggling with not achieving the same numbers as reported in the original papers? Worried about the complicated evaluation process? Don't worry, we've got you covered with an intuitive, easy-to-use interface. Here's a sample snippet demonstrating how to evaluate Human Eval using pass@k (k=[1,10,100]) as the metric:

…

Comparing to this script from HuggingFace, which requires ~230 LOCs to evaluate on pass@k, we only need 14 LOCs to do the same !!!

Loading Preprocessed Data

CodeTF provides the Dataset utility for several well-known datasets, such as CodeXGLUE, Human Eval, MBPP, and APPS. The following is an example of how to load the CodeXGLUE dataset:

python
from codetf.data_utility.codexglue_dataset import CodeXGLUEDataset
from transformers import RobertaTokenizer

tokenizer = RobertaTokenizer.from_pretrained("Salesforce/codet5-base", use_fast=True)
dataset = CodeXGLUEDataset(tokenizer=tokenizer)
train, test, validation = dataset.load(subset="text-to-code")

The train, test, validation are returned in form of Pytorch tensor to provide the flexilbity for the users to wrap it into higher-lever wrapper for their own use cases.

Code Utilities

In addition to providing utilities for LLMs, CodeTF also equips users with tools for effective source code manipulation. This is crucial in the code intelligence pipeline, where operations like parsing code into an Abstract Syntax Tree (AST) or extracting code attributes (such as function names or identifiers) are often required (CodeT5). These tasks can be challenging to execute, especially when setup and multi-language support is needed. Our code utility interface offers a streamlined solution, facilitating easy parsing and attribute extraction from code across 15+ languages.

AST Parser in Multiple Languages

CodeTF includes AST parsers compatible with numerous programming languages. Here's an example showcasing the parsing of Apex code into an AST:

python
from codetf.code_utility.apex.apex_code_utility import ApexCodeUtility

apex_code_utility = ApexCodeUtility()

sample_code = """
    public class SampleClass {    
        public Integer myNumber;
        
        **
        * This is a method that returns the value of myNumber.
        * @return An integer value
        */
        public Integer getMyNumber() {
            // Return the current value of myNumber
            return this.myNumber;
        }
    }
"""
ast = apex_code_utility.parse(sample_code)

# This will print the tree-sitter AST object
print(ast)

Then you can traverse the tree using the interface from py-tree-sitter

root_node = ast.root_

Issues· 28 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Pythonai4codeai4secode-generationcode-intelligence

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库