Views
No views yet
.pte files, split the way Whisper is on this shelf and for the same reason:
the vision tower and the text encoder run once per image, the decoder runs once per
generated token.vision : pixel_values (1,3,768,768) -> image_features (1,577,1024)
encoder: (image_features, input_ids (1,32), mask (1,32)) -> hidden (1,609,1024)
decoder: (hidden, mask (1,32), decoder_input_ids (1,128)) -> logits (1,128,51328)| part | build | file | MB | corr vs fp32 eager | Mac ms* |
|---|---|---|---|---|---|
| vision | XNNPACK fp32 | florence2_large_vision_xnnpack_fp32.pte | 1452.6 | 1.000000 | 803.9 |
| vision | Core ML (iOS) | florence2_large_vision_coreml_all.pte | 729.5 | 0.999953 | 238.2 |
| encoder | XNNPACK fp32 | florence2_large_encoder_xnnpack_fp32.pte | 831.8 | 1.000000 | 144.4 |
| encoder | Core ML (iOS) | florence2_large_encoder_coreml_all.pte | 409.2 | 0.999944 | 43.1 |
| decoder | XNNPACK fp32 | florence2_large_decoder_xnnpack_fp32.pte | 1243.8 | 1.000000 | 85.8 |
| decoder | Core ML (iOS) | florence2_large_decoder_coreml_all.pte | 509.5 | 0.999980 | 13.8 |
.pte.<CAPTION>:| task | the sentence that is actually tokenised |
|---|---|
<CAPTION> | What does the image describe? |
<DETAILED_CAPTION> | Describe in detail what is shown in the image. |
<MORE_DETAILED_CAPTION> | Describe with a paragraph what is shown in the image. |
<OD> | Locate the objects with category name in the image. |
<DENSE_REGION_CAPTION> | Locate the objects in the image, with their descriptions. |
<REGION_PROPOSAL> | Locate the region proposals in the image. |
<OCR> | What is the text in the image? |
<OCR_WITH_REGION> | What is the text in the image, with regions? |
<CAPTION_TO_PHRASE_GROUNDING> | Locate the phrases in the caption: {your caption} |
<OPEN_VOCABULARY_DETECTION> | Locate {your phrase} in the image. |
<s> sentence </s> with the repo's tokenizer, right-pad to 32
with the pad id (1), and build an attention_mask that is 1 on the real tokens and 0 on
the padding. Run the encoder .pte with (image_features, input_ids, mask).<image>×577 + <s> prompt </s>, and because the image tokens are a
contiguous prefix, the encoder here concatenates the vision features in front of the text
embeddings instead of scattering them into placeholder positions.(1,128) int64 window with
the pad id, write the decoder start token (2) at position 0, then for step t:logits = decoder(hidden, mask, window) # mask is the same one the encoder took
ban every token that would repeat a 3-gram already in the output # <- see below
next = argmax(logits[0, t])
if next == 2: stop # </s>
window[0, t + 1] = nextno_repeat_ngram_size: 3 from the model's generation_config.json is load-bearing on
this size. Large's decoder returns <s> as its argmax three times in a row on most
images. The ban on repeating that 3-gram is the only thing that moves it on to the
caption — a plain argmax loop emits <s> forever and returns an empty string. On five
test photographs it did so every time, before and after conversion, in eager PyTorch as
well as through the .pte. Base tolerates the omission and large does not, so implement
the rule.<loc_N> tokens, N in
0..999. Four in a row are a box, and each coordinate is (N + 0.5) × side / 1000 in the
original image's pixels — side being the image's width for x and its height for y, not
768.Florence2ForConditionalGeneration exactly: composition
max_abs_diff 0.000e+00 against the full model's logits on the same image and prompt..pte files, greedy <CAPTION> on five photographs against
the same decoding in eager PyTorch: fp32 5/5 and Core ML 5/5 captions identical,
character for character.A person's hands playing a piano with the words Lauberger and Gloss written on it.
A long wooden pier stretching out into the ocean on a sunny day.
A forest of dead trees in the middle of a forest.
A road in the middle of a pine forest lined with tall trees.
A couple of wooden benches sitting on top of a park bench covered in leaves.python convert/check_florence2.py large fp32 # or coreml_allif hidden_states.dtype == torch.float16 and not torch.isfinite(hidden_states).all():torch.export cannot answer, and export stops with
GuardOnDataDependentSymNode.Florence2ForConditionalGeneration prints a load report where
every key is unexpected and hands back a randomly initialised model without raising.torch_dtype: float16 and transformers honours it, so
from_pretrained must be given dtype=torch.float32 explicitly.