Files changed (2) hide show
  1. README.md +12 -5
  2. config.json +1 -1
README.md CHANGED
@@ -27,7 +27,7 @@ Resources and Technical Documentation:
27
 
28
  ## How to Get Started with the Model
29
 
30
- Use the code below to get started with the model.
31
 
32
  ```python
33
  import requests
@@ -36,7 +36,11 @@ from PIL import Image
36
  from transformers import AutoProcessor, AutoModelForCausalLM
37
 
38
 
39
- model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True)
 
 
 
 
40
  processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True)
41
 
42
  prompt = "<OD>"
@@ -44,7 +48,7 @@ prompt = "<OD>"
44
  url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
45
  image = Image.open(requests.get(url, stream=True).raw)
46
 
47
- inputs = processor(text=prompt, images=image, return_tensors="pt")
48
 
49
  generated_ids = model.generate(
50
  input_ids=inputs["input_ids"],
@@ -78,7 +82,10 @@ from PIL import Image
78
  from transformers import AutoProcessor, AutoModelForCausalLM
79
 
80
 
81
- model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True)
 
 
 
82
  processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True)
83
 
84
  url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
@@ -89,7 +96,7 @@ def run_example(task_prompt, text_input=None):
89
  prompt = task_prompt
90
  else:
91
  prompt = task_prompt + text_input
92
- inputs = processor(text=prompt, images=image, return_tensors="pt")
93
  generated_ids = model.generate(
94
  input_ids=inputs["input_ids"],
95
  pixel_values=inputs["pixel_values"],
 
27
 
28
  ## How to Get Started with the Model
29
 
30
+ Use the code below to get started with the model. All models are trained with float16.
31
 
32
  ```python
33
  import requests
 
36
  from transformers import AutoProcessor, AutoModelForCausalLM
37
 
38
 
39
+
40
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
41
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
42
+
43
+ model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large-ft", torch_dtype=torch_dtype, trust_remote_code=True).to(device)
44
  processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True)
45
 
46
  prompt = "<OD>"
 
48
  url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
49
  image = Image.open(requests.get(url, stream=True).raw)
50
 
51
+ inputs = processor(text=prompt, images=image, return_tensors="pt").to(device, torch_dtype)
52
 
53
  generated_ids = model.generate(
54
  input_ids=inputs["input_ids"],
 
82
  from transformers import AutoProcessor, AutoModelForCausalLM
83
 
84
 
85
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
86
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
87
+
88
+ model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large-ft", torch_dtype=torch_dtype, trust_remote_code=True).to(device)
89
  processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True)
90
 
91
  url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
 
96
  prompt = task_prompt
97
  else:
98
  prompt = task_prompt + text_input
99
+ inputs = processor(text=prompt, images=image, return_tensors="pt").to(device, torch_dtype)
100
  generated_ids = model.generate(
101
  input_ids=inputs["input_ids"],
102
  pixel_values=inputs["pixel_values"],
config.json CHANGED
@@ -79,7 +79,7 @@
79
  "image_feature_source": ["spatial_avg_pool", "temporal_avg_pool"]
80
  },
81
  "vocab_size": 51289,
82
- "torch_dtype": "float32",
83
  "transformers_version": "4.41.0.dev0",
84
  "is_encoder_decoder": true
85
  }
 
79
  "image_feature_source": ["spatial_avg_pool", "temporal_avg_pool"]
80
  },
81
  "vocab_size": 51289,
82
+ "torch_dtype": "float16",
83
  "transformers_version": "4.41.0.dev0",
84
  "is_encoder_decoder": true
85
  }