Instructions to use yuta24/ui-test-vision-2b-alpha with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use yuta24/ui-test-vision-2b-alpha with PEFT:
Task type is invalid.
- MLX
How to use yuta24/ui-test-vision-2b-alpha with MLX:
# Make sure mlx-vlm is installed # pip install --upgrade mlx-vlm from mlx_vlm import load, generate from mlx_vlm.prompt_utils import apply_chat_template from mlx_vlm.utils import load_config # Load the model model, processor = load("yuta24/ui-test-vision-2b-alpha") config = load_config("yuta24/ui-test-vision-2b-alpha") # Prepare input image = ["http://images.cocodataset.org/val2017/000000039769.jpg"] prompt = "Describe this image." # Apply chat template formatted_prompt = apply_chat_template( processor, config, prompt, num_images=1 ) # Generate output output = generate(model, processor, formatted_prompt, image) print(output) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Download code/glint/glint_model.py from yuta24/ui-test-vision-2b-alpha: direct link, hf CLI and curl.
- Browser
- Download file 2.58 kB
-
https://huggingface.co/yuta24/ui-test-vision-2b-alpha/resolve/main/code/glint/glint_model.py
- Command line
-
hf download hf://yuta24/ui-test-vision-2b-alpha/code/glint/glint_model.py
-
curl -L -o glint_model.py https://huggingface.co/yuta24/ui-test-vision-2b-alpha/resolve/main/code/glint/glint_model.py
2.58 kB
| """ClefModel + optional BoxHead. Kept free of transformers/peft imports so it can be unit-tested with a mock backbone.""" | |
| from __future__ import annotations | |
| from typing import Any | |
| import torch | |
| from .joint_schema_model import ClefModel, JointSchemaHead | |
| from .box import BoxHead, BoxPrediction | |
| class GlintModel(ClefModel): | |
| """`forward(batch)` returns the joint-schema logits exactly like ClefModel (list per record). | |
| `decide(batch)` returns `(logits, boxes)`; `boxes[i]` is a BoxPrediction or None.""" | |
| def __init__(self, language_model: Any, head: JointSchemaHead, box_head: BoxHead | None = None) -> None: | |
| super().__init__(language_model, head) | |
| self.box_head = box_head | |
| def _base_model(self): | |
| lm = self.language_model | |
| return lm.get_base_model() if hasattr(lm, "get_base_model") else lm | |
| def _hidden(self, batch: dict[str, Any]): | |
| base_model = self._base_model() | |
| media = batch.get("media") or {} | |
| text_model = base_model.model | |
| if not media and hasattr(text_model, "language_model"): | |
| text_model = text_model.language_model | |
| outputs = text_model(input_ids=batch["input_ids"], attention_mask=batch["attention_mask"], | |
| use_cache=False, return_dict=True, **media) | |
| return outputs.last_hidden_state, base_model | |
| def decide(self, batch: dict[str, Any]) -> tuple[list[list[torch.Tensor]], list[BoxPrediction | None]]: | |
| hidden, base_model = self._hidden(batch) | |
| records = batch["records"] | |
| logits: list[list[torch.Tensor]] = [[] for _ in records] | |
| keep = [i for i, r in enumerate(records) if r.questions] | |
| if keep: | |
| sel = keep if len(keep) < len(records) else slice(None) | |
| out = self.head(hidden[sel], batch["input_ids"][sel], batch["attention_mask"][sel], [records[i] for i in keep], | |
| base_model.get_output_embeddings().weight) | |
| for i, z in zip(keep, out): | |
| logits[i] = z | |
| boxes: list[BoxPrediction | None] = [None] * len(records) | |
| if any(getattr(r, "box_questions", ()) for r in records): | |
| if self.box_head is None: | |
| raise ValueError("record has box questions but this checkpoint has no box head (train with --box-head on)") | |
| boxes = self.box_head(hidden, batch["attention_mask"], records) | |
| return logits, boxes | |
| def forward(self, batch: dict[str, Any]) -> list[list[torch.Tensor]]: | |
| return self.decide(batch)[0] | |