BERTs are Generative In-Context Learners
Paper • 2406.04823 • Published • 1
How to use ltg/deberta-xxlarge-fixed with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="ltg/deberta-xxlarge-fixed", trust_remote_code=True) # Load model directly
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("ltg/deberta-xxlarge-fixed", trust_remote_code=True, dtype="auto")How to use ltg/deberta-xxlarge-fixed with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "ltg/deberta-xxlarge-fixed"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "ltg/deberta-xxlarge-fixed",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/ltg/deberta-xxlarge-fixed
How to use ltg/deberta-xxlarge-fixed with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "ltg/deberta-xxlarge-fixed" \
--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": "ltg/deberta-xxlarge-fixed",
"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 "ltg/deberta-xxlarge-fixed" \
--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": "ltg/deberta-xxlarge-fixed",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use ltg/deberta-xxlarge-fixed with Docker Model Runner:
docker model run hf.co/ltg/deberta-xxlarge-fixed
# Load model directly
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("ltg/deberta-xxlarge-fixed", trust_remote_code=True, dtype="auto")This is deberta-v2-xxlarge updated to implement the AutoModelForCausalLM class, enabling it to generate text. This implementation is based on our paper "BERTs are Generative In-Context Learners".
This repository also fixes three bugs in the original HF implementation of DeBERTa:
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("ltg/deberta-xxlarge-fixed", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("ltg/deberta-xxlarge-fixed", trust_remote_code=True).cuda().eval()
prompt = """German: Hallo, wie geht es Ihnen heute?
English:"""
prompt = prompt.replace('\n', '\\n ')
input_ids = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).input_ids.cuda()
prediction = model.generate(
input_ids,
num_beams=4,
do_sample=False,
use_cache=None,
max_new_tokens=64,
eos_token_id=tokenizer(".\\", add_special_tokens=False).input_ids[1:]
)
prediction = prediction[0, input_ids.size(1):]
prediction = tokenizer.decode(prediction).rstrip('\\')
# Expected output: "Hello, how are you doing today?"
print(prediction)
If you find DeBERTa useful for your work, please cite the following paper:
@inproceedings{
samuel2024berts,
title={{BERT}s are Generative In-Context Learners},
author={David Samuel},
booktitle={The Thirty-eighth Annual Conference on Neural Information Processing Systems},
year={2024},
url={https://openreview.net/forum?id=BCA9NMZkLS}
}
@inproceedings{he2021deberta,
title={{DeBERTa}: Decoding-enhanced {BERT} with disentangled attention},
author={Pengcheng He and Xiaodong Liu and Jianfeng Gao and Weizhu Chen},
booktitle={International Conference on Learning Representations},
year={2021},
url={https://openreview.net/forum?id=XPZIaotutsD}
}
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ltg/deberta-xxlarge-fixed", trust_remote_code=True)