Repository: huggingface/transformers
Pull request: [Kosmos 2.5] Rename checkpoints

# What does this PR do?

This PR renames all instances of `ydshieh/kosmos-2.5` to `microsoft/kosmos-2.5`.

cc @ydshieh feel free to take over this PR

To do:

- [x] add KOSMOS-2.5 chat to the docs


Changed files:
filename: docs/source/en/model_doc/kosmos2_5.md
patch: @@ -9,7 +9,7 @@ Unless required by applicable law or agreed to in writing, software distributed
 an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 specific language governing permissions and limitations under the License.
 -->
-*This model was released on 2023-09-23 and added to Hugging Face Transformers on 2025-08-19.*
+*This model was released on {release_date} and added to Hugging Face Transformers on 2025-08-19.*
 
 <div style="float: right;">
     <div class="flex flex-wrap space-x-1">
@@ -48,14 +48,14 @@ import requests
 from PIL import Image, ImageDraw
 from transformers import AutoProcessor, Kosmos2_5ForConditionalGeneration, infer_device
 
-repo = "ydshieh/kosmos-2.5"
-device = f"{infer_device()}:0"
+repo = "microsoft/kosmos-2.5"
+device = "cuda:0"
 dtype = torch.bfloat16
 model = Kosmos2_5ForConditionalGeneration.from_pretrained(repo, device_map=device, dtype=dtype)
 processor = AutoProcessor.from_pretrained(repo)
 
 # sample image
-url = "https://huggingface.co/ydshieh/kosmos-2.5/resolve/main/receipt_00008.png"
+url = "https://huggingface.co/microsoft/kosmos-2.5/resolve/main/receipt_00008.png"
 image = Image.open(requests.get(url, stream=True).raw)
 
 prompt = "<md>"
@@ -87,14 +87,14 @@ import requests
 from PIL import Image, ImageDraw
 from transformers import AutoProcessor, Kosmos2_5ForConditionalGeneration, infer_device
 
-repo = "ydshieh/kosmos-2.5"
-device = f"{infer_device()}:0"
+repo = "microsoft/kosmos-2.5"
+device = "cuda:0"
 dtype = torch.bfloat16
 model = Kosmos2_5ForConditionalGeneration.from_pretrained(repo, device_map=device, dtype=dtype)
 processor = AutoProcessor.from_pretrained(repo)
 
 # sample image
-url = "https://huggingface.co/ydshieh/kosmos-2.5/resolve/main/receipt_00008.png"
+url = "https://huggingface.co/microsoft/kosmos-2.5/resolve/main/receipt_00008.png"
 image = Image.open(requests.get(url, stream=True).raw)
 
 # bs = 1
@@ -160,12 +160,52 @@ image.save("output.png")
 </hfoptions>
 
 
-## Example
-**Markdown Task:** For usage instructions, please refer to [md.py](https://huggingface.co/ydshieh/kosmos-2.5/blob/main/md.py).
+## Chat version
 
-**OCR Task:** For usage instructions, please refer to [ocr.py](https://huggingface.co/ydshieh/kosmos-2.5/blob/main/ocr.py).
+The authors also released Kosmos-2.5 Chat, which is a chat version optimized for document understanding. You can use it like so:
 
+```python
+import re
+import torch
+import requests
+from PIL import Image, ImageDraw
+from transformers import AutoProcessor, Kosmos2_5ForConditionalGeneration
+
+repo = "microsoft/kosmos-2.5-chat"
+device = "cuda:0"
+dtype = torch.bfloat16
+
+model = Kosmos2_5ForConditionalGeneration.from_pretrained(repo,
+                                                          device_map=device,
+                                                          torch_dtype=dtype,
+                                                          attn_implementation="flash_attention_2")
+processor = AutoProcessor.from_pretrained(repo)
 
+# sample image
+url = "https://huggingface.co/microsoft/kosmos-2.5/resolve/main/receipt_00008.png"
+
+image = Image.open(requests.get(url, stream=True).raw)
+
+question = "What is the sub total of the receipt?"
+template = "<md>A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: {} ASSISTANT:"
+prompt = template.format(question)
+inputs = processor(text=prompt, images=image, return_tensors="pt")
+
+height, width = inputs.pop("height"), inputs.pop("width")
+raw_width, raw_height = image.size
+scale_height = raw_height / height
+scale_width = raw_width / width
+
+inputs = {k: v.to(device) if v is not None else None for k, v in inputs.items()}
+inputs["flattened_patches"] = inputs["flattened_patches"].to(dtype)
+generated_ids = model.generate(
+    **inputs,
+    max_new_tokens=1024,
+)
+
+generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)
+print(generated_text[0])
+```
 
 ## Kosmos2_5Config
 

filename: src/transformers/models/kosmos2_5/modeling_kosmos2_5.py
patch: @@ -1730,13 +1730,13 @@ def forward(
         >>> import torch
         >>> from transformers import AutoProcessor, Kosmos2_5ForConditionalGeneration
 
-        >>> repo = "ydshieh/kosmos-2.5"
+        >>> repo = "microsoft/kosmos-2.5"
         >>> device = "cuda:0"
         >>> dtype = torch.bfloat16 # torch.float16
         >>> model = Kosmos2_5ForConditionalGeneration.from_pretrained(repo, device_map=device, dtype=dtype)
         >>> processor = AutoProcessor.from_pretrained(repo)
 
-        >>> url = "https://huggingface.co/ydshieh/kosmos-2.5/resolve/main/receipt_00008.png"
+        >>> url = "https://huggingface.co/microsoft/kosmos-2.5/resolve/main/receipt_00008.png"
 
         >>> image = Image.open(requests.get(url, stream=True).raw)
 

filename: tests/models/kosmos2_5/test_modeling_kosmos2_5.py
patch: @@ -523,7 +523,7 @@ def check_same_values(layer_1, layer_2):
 
     @slow
     def test_model_from_pretrained(self):
-        model_name = "ydshieh/kosmos-2.5"
+        model_name = "microsoft/kosmos-2.5"
         model = Kosmos2_5Model.from_pretrained(model_name)
         self.assertIsNotNone(model)
 
@@ -669,11 +669,11 @@ def run_example(self, prompt, image, model, processor):
         return generated_ids, generated_text
 
     def test_eager(self):
-        url = "https://huggingface.co/ydshieh/kosmos-2.5/resolve/main/receipt_00008.png"
+        url = "https://huggingface.co/microsoft/kosmos-2.5/resolve/main/receipt_00008.png"
         image = Image.open(requests.get(url, stream=True).raw)
 
         dtype = torch.bfloat16
-        repo = "ydshieh/kosmos-2.5"
+        repo = "microsoft/kosmos-2.5"
         model = Kosmos2_5ForConditionalGeneration.from_pretrained(
             repo, device_map=torch_device, dtype=dtype, attn_implementation="eager"
         )
@@ -706,11 +706,11 @@ def test_eager(self):
         self.assertListEqual(generated_text, EXPECTED_TEXT[self.cuda_compute_capability_major_version])
 
     def test_sdpa(self):
-        url = "https://huggingface.co/ydshieh/kosmos-2.5/resolve/main/receipt_00008.png"
+        url = "https://huggingface.co/microsoft/kosmos-2.5/resolve/main/receipt_00008.png"
         image = Image.open(requests.get(url, stream=True).raw)
 
         dtype = torch.bfloat16
-        repo = "ydshieh/kosmos-2.5"
+        repo = "microsoft/kosmos-2.5"
         model = Kosmos2_5ForConditionalGeneration.from_pretrained(
             repo, device_map=torch_device, dtype=dtype, attn_implementation="sdpa"
         )
@@ -747,11 +747,11 @@ def test_sdpa(self):
     @pytest.mark.flash_attn_test
     @slow
     def test_FA2(self):
-        url = "https://huggingface.co/ydshieh/kosmos-2.5/resolve/main/receipt_00008.png"
+        url = "https://huggingface.co/microsoft/kosmos-2.5/resolve/main/receipt_00008.png"
         image = Image.open(requests.get(url, stream=True).raw)
 
         dtype = torch.bfloat16
-        repo = "ydshieh/kosmos-2.5"
+        repo = "microsoft/kosmos-2.5"
         model = Kosmos2_5ForConditionalGeneration.from_pretrained(
             repo,
             device_map=torch_device,

filename: tests/models/kosmos2_5/test_processor_kosmos2_5.py
patch: @@ -52,7 +52,7 @@ class Kosmos2_5ProcessorTest(ProcessorTesterMixin, unittest.TestCase):
     def setUp(self):
         self.tmpdirname = tempfile.mkdtemp()
         image_processor = Kosmos2_5ImageProcessor()
-        tokenizer = AutoTokenizer.from_pretrained("ydshieh/kosmos-2.5")
+        tokenizer = AutoTokenizer.from_pretrained("microsoft/kosmos-2.5")
         processor = Kosmos2_5Processor(image_processor, tokenizer)
         processor.save_pretrained(self.tmpdirname)
 
@@ -67,7 +67,7 @@ def tearDown(self):
 
     def test_image_procesor_load_save_reload(self):
         # make sure load from Hub repo. -> save -> reload locally work
-        image_processor = Kosmos2_5ImageProcessor.from_pretrained("ydshieh/kosmos-2.5")
+        image_processor = Kosmos2_5ImageProcessor.from_pretrained("microsoft/kosmos-2.5")
         with TemporaryDirectory() as tmp_dir:
             image_processor.save_pretrained(tmp_dir)
             reloaded_image_processor = Kosmos2_5ImageProcessor.from_pretrained(tmp_dir)
@@ -120,7 +120,7 @@ def test_tokenizer_decode(self):
         self.assertListEqual(decoded_tok, decoded_processor)
 
     def test_can_load_various_tokenizers(self):
-        for checkpoint in ["ydshieh/kosmos-2.5"]:
+        for checkpoint in ["microsoft/kosmos-2.5"]:
             processor = AutoProcessor.from_pretrained(checkpoint)
             tokenizer = AutoTokenizer.from_pretrained(checkpoint)
             self.assertEqual(processor.tokenizer.__class__, tokenizer.__class__)
@@ -300,7 +300,7 @@ def test_structured_kwargs_nested_from_dict(self):
     @require_torch
     def test_full_processor(self):
         url = "https://huggingface.co/kirp/kosmos2_5/resolve/main/receipt_00008.png"
-        processor = AutoProcessor.from_pretrained("ydshieh/kosmos-2.5")
+        processor = AutoProcessor.from_pretrained("microsoft/kosmos-2.5")
         texts = ["<md>", "<ocr>"]
         expected_input_ids = [
             [100288],

filename: tests/models/mistral3/test_modeling_mistral3.py
patch: @@ -334,7 +334,7 @@ def test_mistral3_integration_batched_generate(self):
                 {
                     "role": "user",
                     "content": [
-                        {"type": "image", "url": "https://huggingface.co/ydshieh/kosmos-2.5/resolve/main/view.jpg"},
+                        {"type": "image", "url": "https://huggingface.co/microsoft/kosmos-2.5/resolve/main/view.jpg"},
                         {"type": "text", "text": "Write a haiku for this image"},
                     ],
                 },
@@ -402,7 +402,7 @@ def test_mistral3_integration_batched_generate_multi_image(self):
                 {
                     "role": "user",
                     "content": [
-                        {"type": "image", "url": "https://huggingface.co/ydshieh/kosmos-2.5/resolve/main/view.jpg"},
+                        {"type": "image", "url": "https://huggingface.co/microsoft/kosmos-2.5/resolve/main/view.jpg"},
                         {"type": "text", "text": "Write a haiku for this image"},
                     ],
                 },
@@ -413,11 +413,11 @@ def test_mistral3_integration_batched_generate_multi_image(self):
                     "content": [
                         {
                             "type": "image",
-                            "url": "https://huggingface.co/ydshieh/kosmos-2.5/resolve/main/Statue-of-Liberty-Island-New-York-Bay.jpg",
+                            "url": "https://huggingface.co/microsoft/kosmos-2.5/resolve/main/Statue-of-Liberty-Island-New-York-Bay.jpg",
                         },
                         {
                             "type": "image",
-                            "url": "https://huggingface.co/ydshieh/kosmos-2.5/resolve/main/golden-gate-bridge-san-francisco-purple-flowers-california-echium-candicans-36805947.jpg",
+                            "url": "https://huggingface.co/microsoft/kosmos-2.5/resolve/main/golden-gate-bridge-san-francisco-purple-flowers-california-echium-candicans-36805947.jpg",
                         },
                         {
                             "type": "text",