Instructions to use nagbhaskar55/gemma-2-2b-qa-RLAIF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nagbhaskar55/gemma-2-2b-qa-RLAIF with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="nagbhaskar55/gemma-2-2b-qa-RLAIF") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("nagbhaskar55/gemma-2-2b-qa-RLAIF") model = AutoModelForCausalLM.from_pretrained("nagbhaskar55/gemma-2-2b-qa-RLAIF", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use nagbhaskar55/gemma-2-2b-qa-RLAIF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nagbhaskar55/gemma-2-2b-qa-RLAIF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nagbhaskar55/gemma-2-2b-qa-RLAIF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/nagbhaskar55/gemma-2-2b-qa-RLAIF
- SGLang
How to use nagbhaskar55/gemma-2-2b-qa-RLAIF with 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 "nagbhaskar55/gemma-2-2b-qa-RLAIF" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nagbhaskar55/gemma-2-2b-qa-RLAIF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "nagbhaskar55/gemma-2-2b-qa-RLAIF" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nagbhaskar55/gemma-2-2b-qa-RLAIF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use nagbhaskar55/gemma-2-2b-qa-RLAIF with Docker Model Runner:
docker model run hf.co/nagbhaskar55/gemma-2-2b-qa-RLAIF
gemma-2-2b-qa-RLAIF
RLAIF (GRPO) applied to
thesreedath/gemma-2-2b-qa-sft, a QA-SFT model, to sharpen answer
quality on closed-book (question only) prompts.
Results
| metric | value |
|---|---|
| mean reward, first half of training | 0.8839 |
| mean reward, last half | 1.1455 |
| reward gain | +0.2616 |
| mean KL to the frozen SFT reference | -0.021 |
300 prompts x group of 4, 75 steps, KL beta 0.04, in 880s.
How it was trained
RLAIF via GRPO. For each prompt the policy samples a group of 4 answers; a reward model trained on AI-generated preferences scores them; the advantage is each sample's reward minus the group mean, divided by the group standard deviation. GRPO rather than PPO because it needs no value network, so the policy, its frozen reference and the reward model fit together and the run stays short.
The reward model is a 125M backbone with a scalar head, trained by Bradley-Terry loss on all 600 preference pairs. It reached 93.3% accuracy on 60 held-out pairs (chance is 50%, and it measured 53.3% before training).
Preference data
600 triplets (prompt / chosen / rejected), 300 grounded and 300 closed-book. This model trained on the closed_book half, because that is the distribution it was supervised-fine-tuned on.
The rejected answer in each pair carries exactly one deliberately induced flaw, drawn evenly from six modes that these models actually exhibit: a wrong figure, an unsupported claim, vagueness, rambling repetition, a partial answer, and a false refusal. An LLM judge then confirmed the ordering with the two answers shown in randomised positions, so it could not score well by always choosing the first. Pairs the judge disagreed with, or was unconfident about, were dropped.
Prompt format
This model expects gemma_chat:
<bos><start_of_turn>user\n{question}<end_of_turn>\n<start_of_turn>model\n
The format was established empirically, by scoring known-good answers under competing templates and comparing generation behaviour -- not assumed from the tokenizer.
Limits
600 preference pairs is a small budget for preference optimization. Expect sharper formatting, less padding and more consistent refusals -- not new capability. Preference labels come from an LLM judge, so the model inherits that judge's blind spots. Not legal or financial advice.
- Downloads last month
- 22
Model tree for nagbhaskar55/gemma-2-2b-qa-RLAIF
Base model
thesreedath/gemma-2-2b-qa-sft