kimihailv commited on
Commit
262cb21
1 Parent(s): 00cf28a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +16 -30
README.md CHANGED
@@ -39,36 +39,22 @@ from uform.gen_model import VLMForCausalLM, VLMProcessor
39
  model = VLMForCausalLM.from_pretrained("unum-cloud/uform-gen-chat")
40
  processor = VLMProcessor.from_pretrained("unum-cloud/uform-gen-chat")
41
 
42
- messages = [
43
- {"role": "system", "content": "You are a helpful assistant."},
44
- {"role": "user", "content": "<image> {Your message}"}
45
- ]
46
-
47
- image = processor.image_processor(Image.open("zebra.jpg")).unsqueeze(0)
48
-
49
- input_ids = processor.tokenizer.apply_chat_template(
50
- messages, return_tensors="pt", add_generation_prompt=True
51
- )
52
-
53
- attention_mask = torch.ones(1, input_ids.shape[1] + processor.num_image_latents - 1)
54
-
55
- inputs = {
56
- "input_ids": input_ids,
57
- "attention_mask": attention_mask,
58
- "images": image,
59
- }
60
-
61
- outputs = model.generate(
62
- **inputs,
63
- do_sample=False,
64
- use_cache=True,
65
- max_new_tokens=1024,
66
- eos_token_id=32001,
67
- pad_token_id=processor.tokenizer.pad_token_id,
68
- )
69
-
70
- message = processor.batch_decode(outputs[:, inputs["input_ids"].shape[1]:-1])
71
-
72
  ```
73
 
74
 
 
39
  model = VLMForCausalLM.from_pretrained("unum-cloud/uform-gen-chat")
40
  processor = VLMProcessor.from_pretrained("unum-cloud/uform-gen-chat")
41
 
42
+ prompt = "What do you see?"
43
+ image = Image.open("zebra.jpg")
44
+
45
+ inputs = processor(texts=[prompt], images=[image], return_tensors="pt")
46
+ with torch.inference_mode():
47
+ output = model.generate(
48
+ **inputs,
49
+ do_sample=False,
50
+ use_cache=True,
51
+ max_new_tokens=128,
52
+ eos_token_id=32001,
53
+ pad_token_id=processor.tokenizer.pad_token_id
54
+ )
55
+
56
+ prompt_len = inputs["input_ids"].shape[1]
57
+ decoded_text = processor.batch_decode(output[:, prompt_len:])[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  ```
59
 
60