Text Generation
Transformers
Safetensors
English
gemma
dpo
2b
conversational
text-generation-inference
Instructions to use oopere/martra-open-gemma-2b-it-dpo with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use oopere/martra-open-gemma-2b-it-dpo with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="oopere/martra-open-gemma-2b-it-dpo") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("oopere/martra-open-gemma-2b-it-dpo") model = AutoModelForCausalLM.from_pretrained("oopere/martra-open-gemma-2b-it-dpo", 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use oopere/martra-open-gemma-2b-it-dpo with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "oopere/martra-open-gemma-2b-it-dpo" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "oopere/martra-open-gemma-2b-it-dpo", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/oopere/martra-open-gemma-2b-it-dpo
- SGLang
How to use oopere/martra-open-gemma-2b-it-dpo 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 "oopere/martra-open-gemma-2b-it-dpo" \ --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": "oopere/martra-open-gemma-2b-it-dpo", "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 "oopere/martra-open-gemma-2b-it-dpo" \ --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": "oopere/martra-open-gemma-2b-it-dpo", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use oopere/martra-open-gemma-2b-it-dpo with Docker Model Runner:
docker model run hf.co/oopere/martra-open-gemma-2b-it-dpo
| language: | |
| - en | |
| license: mit | |
| library_name: transformers | |
| tags: | |
| - dpo | |
| - 2b | |
| - gemma | |
| datasets: | |
| - argilla/distilabel-capybara-dpo-7k-binarized | |
| pipeline_tag: text-generation | |
| widget: | |
| - text: "3713841893836/4? \nLimit your response to mathematical expressions and symbols." | |
| example_title: 'Return only numbers. ' | |
| - text: A group of 10 people is split into 3 different committees of 3, 4, and 3 people, | |
| respectively. In how many ways can this be done? | |
| example_title: Solve Problem | |
| You can see the process with instructions for creating the model in the notebook: [Aligning_DPO_gemma-2b.ipynb](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/P2-MHF/Aligning_DPO_open_gemma-2b-it.ipynb) | |
| To create it, we started with the [google/gemma-2b-it](https://huggingface.co/google/gemma-2b-it) model and applied DPO alignment using the [distilabel-capybara-dpo-7k-binarized dataset](https://huggingface.co/datasets/argilla/distilabel-capybara-dpo-7k-binarized). | |
| Gemma is a family of lightweight, state-of-the-art open models from Google, built from the same research and technology used to create the Gemini models. | |
| **Row in the Dataset:** | |
| *{'prompt': '<|user|>\nAssist me in calculating 9319357631 plus 595. Numbers and symbols only, please.<|end|>\n<|assistant|>\n', | |
| 'chosen': 'The sum of 9319357631 and 595 is 9319358226.<|end|>\n', | |
| 'rejected': 'The result of adding 9319357631 and 595 is 9319363626.<|end|>\n'}* | |
| **Prompt:** | |
| *3713841893836/4? | |
| Limit your response to mathematical expressions and symbols.* | |
| **Response from the Base model:** | |
| *To find the result of the division, we can simply divide the given number by 4: | |
| $$ | |
| \frac{3713841893836}{4} = 928460473459* | |
| **Response from the fine-tuned model:** | |
| *3713841893836 ÷ 4 = 928460473459* | |
| If you want to see how the model was created, you can check out the [repository](https://github.com/peremartra/Large-Language-Model-Notebooks-Course) where the book's notebooks are kept up-to-date. |