yujiepan commited on
Commit
9424f32
·
verified ·
1 Parent(s): 9851b99

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +41 -1
README.md CHANGED
@@ -15,7 +15,47 @@ This tiny model is for debugging. It is randomly initialized with the config ada
15
  ### Example usage:
16
 
17
  ```python
18
- {code_to_run.strip()}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  ```
20
 
21
  ### Codes to create this repo:
 
15
  ### Example usage:
16
 
17
  ```python
18
+ import torch
19
+
20
+ from transformers import pipeline
21
+
22
+ model_id = "yujiepan/gemma-3n-tiny-random-dim4"
23
+ pipe = pipeline(
24
+ task="image-text-to-text",
25
+ model=model_id,
26
+ device=0,
27
+ torch_dtype=torch.bfloat16
28
+ )
29
+
30
+ # temporary patch for audio tower
31
+ from accelerate.hooks import ModelHook, add_hook_to_module
32
+
33
+ class EnsureDtype(ModelHook):
34
+ def pre_forward(self, module, *args, **kwargs):
35
+ args = list(args)
36
+ args[0] = args[0].to(module.dtype)
37
+ return super().pre_forward(module, *args, **kwargs)
38
+ add_hook_to_module(pipe.model.audio_tower, EnsureDtype())
39
+
40
+ messages = [
41
+ {
42
+ "role": "system",
43
+ "content": [
44
+ {"type": "text", "text": "You are a helpful assistant."}
45
+ ]
46
+ },
47
+ {
48
+ "role": "user",
49
+ "content": [
50
+ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"},
51
+ # audio is buggy for now: bf16 x fp32
52
+ {"type": "audio", "url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-Audio/glass-breaking-151256.mp3"},
53
+ {"type": "text", "text": "Which image is cuter?"},
54
+ ]
55
+ },
56
+ ]
57
+ result = pipe(messages, min_new_tokens=512, max_new_tokens=512, do_sample=True)
58
+ print(result)
59
  ```
60
 
61
  ### Codes to create this repo: