Better Language Model Inversion by Compactly Representing Next-Token Distributions
Paper • 2506.17090 • Published • 1
How to use dill-lab/pils-32-llama2-chat-7b with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="dill-lab/pils-32-llama2-chat-7b") # Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("dill-lab/pils-32-llama2-chat-7b", dtype="auto")How to use dill-lab/pils-32-llama2-chat-7b with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "dill-lab/pils-32-llama2-chat-7b"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "dill-lab/pils-32-llama2-chat-7b",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/dill-lab/pils-32-llama2-chat-7b
How to use dill-lab/pils-32-llama2-chat-7b with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "dill-lab/pils-32-llama2-chat-7b" \
--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": "dill-lab/pils-32-llama2-chat-7b",
"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 "dill-lab/pils-32-llama2-chat-7b" \
--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": "dill-lab/pils-32-llama2-chat-7b",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use dill-lab/pils-32-llama2-chat-7b with Docker Model Runner:
docker model run hf.co/dill-lab/pils-32-llama2-chat-7b
pip install gradio
pip install git+https://github.com/dill-lab/PILS
import gradio as gr
import torch
from pils.models import InversionFromHiddenStatesModel
MODEL = InversionFromHiddenStatesModel.from_pretrained(
"murtaza/pils-32-llama2-chat-7b")
MODEL.embedder_no_grad=True
MODEL.embedder.max_new_tokens = 64
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
MODEL = MODEL.to(DEVICE)
def invert(user_prompt):
global inp
sys_prompt = ''
inp = MODEL.embedder_tokenizer.apply_chat_template(conversation=[
{"role": "system", "content": sys_prompt},
{"role": "user", "content": user_prompt},
], add_generation_prompt=True, return_dict=True, return_tensors='pt')
inp = {f"embedder_{k}": v.to(DEVICE) for k, v in inp.items()}
output = MODEL.call_embedding_model(**inp)
inp['frozen_embeddings'] = output["embeddings"]
with torch.inference_mode():
out = MODEL.generate(inp, {"max_length": 64})
inverted = MODEL.tokenizer.decode(out[0], skip_special_tokens=True)
generated = MODEL.embedder_tokenizer.decode(output["chosen_tokens"][0].squeeze(), skip_special_tokens=True)
return generated, inverted
demo = gr.Interface(
fn=invert,
inputs=gr.Textbox(label="Secret prompt"),
outputs=(gr.Textbox(label="LLM output"), gr.Textbox(label="Inverter guess"))
)
demo.launch(share=True)
@misc{nazir2025betterlanguagemodelinversion,
title={Better Language Model Inversion by Compactly Representing Next-Token Distributions},
author={Murtaza Nazir and Matthew Finlayson and John X. Morris and Xiang Ren and Swabha Swayamdipta},
year={2025},
eprint={2506.17090},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2506.17090},
}
Repository for the paper Better Language Model Inversion by Compactly Representing Next-Token Distributions.