Image-Text-to-Text
Transformers
Safetensors
gemma3
Generated from Trainer
sft
trl
conversational
text-generation-inference
Instructions to use swap-uniba/user_gemma_3_27b_it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use swap-uniba/user_gemma_3_27b_it with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="swap-uniba/user_gemma_3_27b_it") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("swap-uniba/user_gemma_3_27b_it") model = AutoModelForMultimodalLM.from_pretrained("swap-uniba/user_gemma_3_27b_it", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.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(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use swap-uniba/user_gemma_3_27b_it with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "swap-uniba/user_gemma_3_27b_it" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "swap-uniba/user_gemma_3_27b_it", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/swap-uniba/user_gemma_3_27b_it
- SGLang
How to use swap-uniba/user_gemma_3_27b_it 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 "swap-uniba/user_gemma_3_27b_it" \ --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": "swap-uniba/user_gemma_3_27b_it", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "swap-uniba/user_gemma_3_27b_it" \ --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": "swap-uniba/user_gemma_3_27b_it", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use swap-uniba/user_gemma_3_27b_it with Docker Model Runner:
docker model run hf.co/swap-uniba/user_gemma_3_27b_it
| {{ bos_token }} | |
| {%- set system_prompt = "You are an advanced user simulator. Your objective is to generate realistic and coherent user responses in a dialogue with a recommendation system based on the user persona, interaction history and target item provided. | |
| Use the following guidelines: | |
| 1. Adhere to the user persona: The user's behavior, tone, and responses must align with the specified persona. | |
| 2. Use the tone inferred from the user's past reviews in the interaction history. | |
| 3. Ensure that the user's responses are contextually relevant to the ongoing conversation and the target item. | |
| 4. Maintain coherence and natural flow in the dialogue." -%} | |
| {%- set first_user_prefix = system_prompt + ' | |
| ' -%} | |
| {%- set loop_messages = messages -%} | |
| {%- for message in loop_messages -%} | |
| {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%} | |
| {{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }} | |
| {%- endif -%} | |
| {%- if (message['role'] == 'assistant') -%} | |
| {%- set role = "model" -%} | |
| {%- elif (message['role'] == 'system') -%} | |
| {{ raise_exception("This template is hardcoded and does not accept 'system' messages.") }} | |
| {%- else -%} | |
| {%- set role = message['role'] -%} | |
| {%- endif -%} | |
| {{ '<start_of_turn>' + role + ' | |
| ' + (first_user_prefix if loop.first else "") }} | |
| {%- if message.content is string -%} | |
| {# This handles regular assistant/model responses #} | |
| {{ message.content | trim }} | |
| {%- elif message.content is mapping -%} | |
| # Category | |
| {{ message.content.category | trim }}{{ "\n\n" }} | |
| # User Persona | |
| {{ message.content.user_persona | trim }}{{ "\n" }} | |
| {%- if message.content.interacted_items | length > 0 -%} | |
| {{ "\n\n" }}# Interaction history | |
| {%- for item in message.content.interacted_items -%} | |
| {{ "\n" }}## Item Name: {{ item.item_name | trim }} | |
| ## Description: {{ item.description | trim }} | |
| ## Visual Description: {{ item.visual_description | trim }} | |
| ## Review: {{ item.review | trim }}{{ "\n" }} | |
| {%- endfor -%} | |
| {%- endif -%} | |
| {{ "\n" }} | |
| # Target item | |
| ## Item Name: {{ message.content.target_item.item_name | trim }} | |
| ## Description: {{ message.content.target_item.description | trim }} | |
| ## Visual Description: {{ message.content.target_item.visual_description | trim }} | |
| ## Review: {{ message.content.target_item.review | trim }}{{ "\n" }} | |
| {%- if message.content.messages | length > 0 -%} | |
| {{ "\n\n" }}# Conversation so far | |
| {%- for turn in message.content.messages[-2:] -%} | |
| {%- if turn['role'] == 'assistant' -%} | |
| {{ "\n" }}CRS: "{{turn['content'] | trim}}" | |
| {%- else -%} | |
| {{ "\n" }}USR: "{{turn['content'] | trim}}" | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {{ "\n" }} | |
| {{ "Generate the next user response based on the above information." }} | |
| {%- else -%} | |
| {{ "\nGenerate the first user message based on the above information." }} | |
| {%- endif -%} | |
| {%- else -%} | |
| {{ raise_exception("Invalid content type: must be string, mapping (dict), or iterable (list).") }} | |
| {%- endif -%} | |
| {{ '<end_of_turn> | |
| ' }} | |
| {%- endfor -%} | |
| {%- if add_generation_prompt -%} | |
| {{'<start_of_turn>model | |
| '}} | |
| {%- endif -%} |