Views
No views yet
1%%capture
2!pip install -U bitsandbytes
3
4from transformers import AutoProcessor, AutoModelForImageTextToText
5import torch
6DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
7
8processor = AutoProcessor.from_pretrained("manifestasi/RetinaVLM-300M-DPO")
9model = AutoModelForImageTextToText.from_pretrained("manifestasi/RetinaVLM-300M-DPO",
10 torch_dtype=torch.float16,
11 _attn_implementation="eager").to(DEVICE)
12
13from PIL import Image
14from transformers.image_utils import load_image
15
16
17# Load images
18# image1 = load_image("https://huggingface.co/spaces/HuggingFaceTB/SmolVLM/resolve/main/example_images/rococo.jpg")
19image2 = load_image("/kaggle/input/bandaraaa/799269_1200.jpg")
20
21# Create input messages
22messages = [
23 {
24 "role": "user",
25 "content": [
26 # {"type": "image"},
27 {"type": "image"},
28 {"type": "text",
29 "text": """
30 Instructions :
31 you are visual assistant for blind people, please answer politely and short
32 under 100 words.
33 Prompt :
34 can you direct me to find toilet
35 """}
36 ]
37 },
38]
39
40# Prepare inputs
41prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
42# inputs = processor(text=prompt, return_tensors="pt")
43inputs = processor(text=prompt, images=[image2], return_tensors="pt")
44inputs = inputs.to(DEVICE)
45# Generate outputs
46from time import time
47
48tim1 = time()
49generated_ids = model.generate(**inputs, max_new_tokens=120)
50generated_texts = processor.batch_decode(
51 generated_ids,
52 skip_special_tokens=True,
53)
54tim2 = time()
55print(f"{(tim2 - tim1)} detik")
56print(generated_texts[0].split("Assistant: ")[1])1@inproceedings{rafailov2023direct,
2 title = {{Direct Preference Optimization: Your Language Model is Secretly a Reward Model}},
3 author = {Rafael Rafailov and Archit Sharma and Eric Mitchell and Christopher D. Manning and Stefano Ermon and Chelsea Finn},
4 year = 2023,
5 booktitle = {Advances in Neural Information Processing Systems 36: Annual Conference on Neural Information Processing Systems 2023, NeurIPS 2023, New Orleans, LA, USA, December 10 - 16, 2023},
6 url = {http://papers.nips.cc/paper_files/paper/2023/hash/a85b405ed65c6477a4fe8302b5e06ce7-Abstract-Conference.html},
7 editor = {Alice Oh and Tristan Naumann and Amir Globerson and Kate Saenko and Moritz Hardt and Sergey Levine},
8}1@misc{vonwerra2022trl,
2 title = {{TRL: Transformer Reinforcement Learning}},
3 author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
4 year = 2020,
5 journal = {GitHub repository},
6 publisher = {GitHub},
7 howpublished = {\url{https://github.com/huggingface/trl}}
8}