How to use from
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 "nlpctx/codet5-java-optimizer" \
    --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": "nlpctx/codet5-java-optimizer",
		"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 "nlpctx/codet5-java-optimizer" \
        --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": "nlpctx/codet5-java-optimizer",
		"prompt": "Once upon a time,",
		"max_tokens": 512,
		"temperature": 0.5
	}'
Quick Links

CodeT5-small Java Optimization Model

A fine-tuned Salesforce/codet5-small model for Java code optimization tasks.

Overview

This repository contains a fine-tuned CodeT5-small model specifically trained for Java code optimization. The model takes verbose or inefficient Java code and generates more optimal versions.

Model Information

  • Base Model: Salesforce/codet5-small
  • Training Dataset: nlpctx/java_optimisation
  • Framework: HuggingFace Transformers with Seq2SeqTrainer
  • Training Setup: Dual-GPU DataParallel (Kaggle T4×2)
  • Dataset Size: ~6K training / 680 validation Java optimization pairs
  • Optimization Focus: Java code refactoring and performance improvements

Files

  • config.json - Model configuration
  • generation_config.json - Generation parameters
  • model.safetensors - Model weights (safetensors format)
  • merges.txt - BPE merges file
  • special_tokens_map.json - Special tokens mapping
  • tokenizer_config.json - Tokenizer configuration
  • vocab.json - Vocabulary file

Usage

from transformers import T5ForConditionalGeneration, RobertaTokenizer
import torch

# Load model and tokenizer
model = T5ForConditionalGeneration.from_pretrained("nlpctx/codet5-java-optimizer")
tokenizer = RobertaTokenizer.from_pretrained("nlpctx/codet5-java-optimizer")

# Prepare input Java code
java_code = "your Java code here"
input_ids = tokenizer(java_code, return_tensors="pt").input_ids

# Generate optimized code
with torch.no_grad():
    outputs = model.generate(
        input_ids,
        max_length=512,
        num_beams=4,
        early_stopping=True
    )

optimized_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(optimized_code)

Example Optimizations

The model has been trained to recognize and optimize common Java patterns:

  • Switch Expressions: Converting verbose switch statements to switch expressions
  • Collection Operations: Replacing manual iterator removal with removeIf()
  • String Handling: Optimizing string concatenation with StringBuilder
  • Loop Optimizations: Improving iterative constructs
  • And more...

Training Details

The model was fine-tuned using:

  • Base Model: Salesforce/codet5-small
  • Dataset: nlpctx/java_optimisation from Hugging Face
  • Training Framework: Seq2SeqTrainer with DataParallel
  • Hardware: Kaggle T4×2 (dual GPU)
  • Approach: Standard supervised fine-tuning on Java optimization pairs

License

This model is licensed under the Apache 2.0 license, matching the original Salesforce/codet5-small model.

Acknowledgements

Downloads last month
57
Safetensors
Model size
60.5M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for nlpctx/codet5-java-optimizer

Finetuned
(91)
this model

Dataset used to train nlpctx/codet5-java-optimizer