nlpctx/java_optimisation
Viewer • Updated • 6.8k • 139
How to use nlpctx/codet5-java-optimizer with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="nlpctx/codet5-java-optimizer") # Load model directly
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("nlpctx/codet5-java-optimizer")
model = AutoModelForSeq2SeqLM.from_pretrained("nlpctx/codet5-java-optimizer")How to use nlpctx/codet5-java-optimizer with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "nlpctx/codet5-java-optimizer"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "nlpctx/codet5-java-optimizer",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/nlpctx/codet5-java-optimizer
How to use nlpctx/codet5-java-optimizer with SGLang:
# 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
}'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
}'How to use nlpctx/codet5-java-optimizer with Docker Model Runner:
docker model run hf.co/nlpctx/codet5-java-optimizer
A fine-tuned Salesforce/codet5-small model for Java code optimization tasks.
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.
config.json - Model configurationgeneration_config.json - Generation parametersmodel.safetensors - Model weights (safetensors format)merges.txt - BPE merges filespecial_tokens_map.json - Special tokens mappingtokenizer_config.json - Tokenizer configurationvocab.json - Vocabulary filefrom 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)
The model has been trained to recognize and optimize common Java patterns:
removeIf()StringBuilderThe model was fine-tuned using:
This model is licensed under the Apache 2.0 license, matching the original Salesforce/codet5-small model.
Base model
Salesforce/codet5-small