UForm

unum-cloudApache-2.0活跃维护

轻量级多模态模型库,能同时理解多语言文本和图像,速度比 OpenAI CLIP 和 LLaVA 快 5 倍,适合做图文检索和内容生成。

Pocket-Sized Multimodal AI for content understanding and generation across multilingual texts, images, and 🔜 video, up to 5x faster than OpenAI CLIP and LLaVA 🖼️ & 🖋️

v3.1.4发布于 2025-10-30 23:39 UTC1,252star76fork同步于 2026-11-10 11:49 UTC

怎么上手

由 README 提炼,执行前请确认
pip install uform
硬件要求按 README 说明

README 未说明具体显存要求;示例用 device='cuda' 加载模型,也提到可运行在服务器、智能手机等设备上,PyTorch 依赖较重时可用 ONNX runtime 降低内存占用。

支持 Apple Silicon需要 CUDA支持 ROCm / AMD
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

轻量多模态 AI 库,用小型 Transformer 做图文检索、图像描述和视觉问答

轻量级多模态模型库,能同时理解多语言文本和图像,速度比 OpenAI CLIP 和 LLaVA 快 5 倍,适合做图文检索和内容生成。

核心能力

  • 提供 64 维 Matryoshka 式嵌入,便于快速向量检索
  • 嵌入模型支持 20 多种语言,跨语言召回表现好
  • 生成模型支持聊天、图像描述和 VQA
  • 原生 ONNX 支持,可部署到多平台
  • 嵌入可从 f32 降为 f16 或 i8,召回损失小

容易踩的坑

生成模型需通过 transformers 的 trust_remote_code=True 加载,并额外下载 Hugging Face 权重;嵌入模型默认 dtype 为 bfloat16,旧硬件可能不支持半精度;生成模型示例需手动设置 eos_token_id 和 pad_token_id。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v3.1.4
  1. v3.1.4Release v3.1.4最新正式版2025-10-30 · 2025-10-30 23:39 UTC

    Release: v3.1.4 [skip ci]

    Patch

    • Docs: DGX-B200 benchmarks (284f9f7)
    • Improve: Default to bfloat16 for Torch (0419b54)
    • Make: Upgrade deps for Py 3.10+ (cef4bea)
    • Make: Upgrade CI with uv (0dff0dc)
  2. v3.1.3Release v3.1.32025-09-03 · 2025-09-03 08:30 UTC
    查看更新说明

    Release: v3.1.3 [skip ci]

  3. v3.1.2Release v3.1.22025-06-21 · 2025-06-21 16:14 UTC
    查看更新说明

    Release: v3.1.2 [skip ci]

  4. v3.1.1Release v3.1.12025-01-03 · 2025-01-03 23:11 UTC
    查看更新说明

    Release: v3.1.1 [skip ci]

  5. v3.1.0v3.1 🍏 Apple Neural Engine Optimizations2024-12-20 · 2024-12-20 12:31 UTC
    查看更新说明

    Apple chips provide several functional units capable of high-throughput matrix multiplication and AI inference. Those computeUnits include the CPU, GPU, and the Apple Neural Engine (ANE). A user may naively hope that any typical architecture, like BERT or ViT, should work fine on all of those chips in any of the common quantization forms, like switching from f32 single-precision to bf16 and f16 half-precision floats or i8 and u8 integers. That is not the case. Of all the backends that UForm has been tested on, quantizing the entire model for CoreML was the most challenging task, and Apple became the only platform where we distribute the models in the original precision, which is a pity given a fleet of 2 billion potential target devices running iOS worldwide, almost all of which are in the countries and language groups natively supported by UForm multimodal multilingual embeddings.

    When using @unum-cloud UForm models in Swift, we pass computeUnits: .all to let Apple's scheduler choose the target device itself and treat it as a black-box optimization. However, a better way to do this is if you can explicitly provide models tuned for the Apple Neural Engine. So, together with our friends from @TheStageAI, we've quantized our models to map perfectly to ANE-supported operations with minimal loss in precision, reducing the model size by 2-4x and accelerating inference up to 5x:

    ModelGPU Text E.ANE Text E.GPU Image E.ANE Image E.
    english-small2.53 ms0.53 ms6.57 ms1.23 ms
    english-base2.54 ms0.61 ms18.90 ms3.79 ms
    english-large2.30 ms0.61 ms79.68 ms20.94 ms
    multilingual-base2.34 ms0.50 ms18.98 ms3.77 ms

    On Apple M4 iPad, running iOS 18.2. The batch size is 1, and the model is pre-loaded into memory. The original encoders use f32 single-precision numbers for maximum compatibility and mostly rely on GPU for computation. The quantized encoders use a mixture of i8, f16, and f32 numbers for maximum performance and mostly rely on the Apple Neural Engine (ANE) for computation. The median latency is reported.


    To use them in Swift, check out the docs at unum-cloud.github.io/uform/swift/ or the SwiftSemanticSearch repository for an integrated example with USearch.

    Thanks to @ArnoldMSU, @b1n0, @Aydarkhan, @AndreyAgeev from TheStage.ai for help 👏

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    UForm Chat Preview

    Welcome to UForm, a multimodal AI library that's as versatile as it is efficient. UForm tiny embedding models will help you understand and search visual and textual content across various languages. UForm small generative models, on the other hand, don't only support conversational and chat use-cases, but are great for fast image captioning and Visual Question Answering (VQA). With compact custom pre-trained transformer models, this can run anywhere from your server farm down to your smartphone.

    Features

    • Tiny Embeddings: 64-dimensional Matryoshka-style embeddings for extremely fast search.
    • Throughput: Thanks to the small size, the inference speed is 2-4x faster than competitors.
    • Portable: Models come with native ONNX support, making them easy to deploy on any platform.
    • Quantization Aware: Down-cast embeddings from f32 to i8 without losing much recall.
    • Multilingual: Trained on a balanced dataset, the recall is great across over 20 languages.

    Models

    For accuracy and speed benchmarks refer to the evaluation page.

    Embedding Models

    Generative Models

    Quick Start Examples

    Embedding Models

    First, pip install uform. Then, load the model:

    from uform import get_model, Modality
    
    # Defaults to `dtype='bfloat16'` for ~2x speedup with minimal accuracy loss
    processors, models = get_model('unum-cloud/uform3-image-text-english-small', device='cuda')
    
    model_text = models[Modality.TEXT_ENCODER]
    model_image = models[Modality.IMAGE_ENCODER]
    processor_text = processors[Modality.TEXT_ENCODER]
    processor_image = processors[Modality.IMAGE_ENCODER]
    

    Embed images:

    import requests
    from io import BytesIO
    from PIL import Image
    
    image_url = 'https://media-cdn.tripadvisor.com/media/photo-s/1b/28/6b/53/lovely-armenia.jpg'
    image = Image.open(BytesIO(requests.get(image_url).content))
    image_data = processor_image(image)
    image_features, image_embedding = model_image.encode(image_data, return_features=True)
    

    Embed queries:

    text = 'a cityscape bathed in the warm glow of the sun, with varied architecture and a towering, snow-capped mountain rising majestically in the background'
    text_data = processor_text(text)
    text_features, text_embedding = model_text.encode(text_data, return_features=True)
    

    For more details check out:

    Generative Models

    The generative models are natively compatible with

    from transformers import AutoModel, AutoProcessor
    
    model = AutoModel.from_pretrained('unum-cloud/uform-gen2-dpo', trust_remote_code=True)
    processor = AutoProcessor.from_pretrained('unum-cloud/uform-gen2-dpo', trust_remote_code=True)
    
    prompt = 'Question or Instruction'
    image = Image.open('image.jpg')
    
    inputs = processor(text=[prompt], images=[image], return_tensors='pt')
    
    with torch.inference_mode():
         output = model.generate(
            **inputs,
            do_sample=False,
            use_cache=True,
            max_new_tokens=256,
            eos_token_id=151645,
            pad_token_id=processor.tokenizer.pad_token_id
        )
    prompt_len = inputs['input_ids'].shape[1]
    decoded_text = processor.batch_decode(output[:, prompt_len:])[0]
    

    For more details check out:

    • Python docs on generative models in python/README.md
    • JavaScript docs on generative models 🔜
    • Swift docs on generative models 🔜

    Technical Details

    Down-casting, Quantization, Matryoshka, and Slicing

    Depending on the application, the embeddings can be down-casted to smaller numeric representations without losing much recall. Switching from f32 to f16 is recommended in almost all cases, unless you are running on very old hardware without half-precision support. Switching to i8 with linear scaling is also possible, but will be noticeable in the recall on larger collections with millions of searchable entries. Similarly, for higher-dimensional embeddings (512 or 768), a common strategy is to quantize them into single-bit representations for faster search.

    import numpy as np
    
    f32_embedding: np.ndarray = model.encode_text(text_data, return_features=False)
    f16_embedding: np.ndarray = f32_embedding.astype(np.float16)
    i8_embedding: np.ndarray = (f32_embedding * 127).astype(np.int8)
    b1_embedding: np.ndarray = np.packbits((f32_embedding > 0).astype(np.uint8))
    

    Alternative approach to quantization is to use the Matryoshka embeddings, where the embeddings are sliced into smaller parts, and the search is performed in a hierarchical manner.

    import numpy as np
    
    large_embedding: np.ndarray = model.encode_text(text_data, return_features=False)
    small_embedding: np.ndarray = large_embedding[:, :256]
    tiny_embedding: np.ndarray = large_embedding[:, :64]
    

    Both approaches are natively supported by the USearch vector-search engine and the SimSIMD numerics libraries. When dealing with small collections (up to millions of entries) and looking for low-latency cosine distance calculations, you can achieve 5x-2500x performance improvement over Torch, NumPy, SciPy, and vanilla Python using SimSIMD.

    from simsimd import cosine, hamming
    
    distance: float = cosine(f32_embedding, f32_embedding) # 32x SciPy performance on Apple M2 CPU
    distance: float = cosine(f16_embedding, f16_embedding) # 79x SciPy performance on Apple M2 CPU
    distance: float = cosine(i8_embedding, i8_embedding) # 133x SciPy performance on Apple M2 CPU
    distance: float = hamming(b1_embedding, b1_embedding) # 17x SciPy performance on Apple M2 CPU
    

    Similarly, when dealing with large collections (up to billions of entries per server) and looking for high-throughput search, you can achieve 100x performance improvement over FAISS and other vector-search solutions using USearch. Here are a couple of examples:

    from usearch.index import Index
    
    f32_index = Index(ndim=64, metric='cos', dtype='f32') # for Matryoshka embeddings
    f16_index = Index(ndim=64, metric='cos', dtype='f16') # for Matryoshka embeddings
    i8_index = Index(ndim=256, metric='cos', dtype='i8') # for quantized embeddings
    b1_index = Index(ndim=768, metric='hamming', dtype='b1') # for binary embeddings
    

    Compact Packaging

    PyTorch is a heavy dependency to carry, especially if you run on Edge or IoT devices. Using vanilla ONNX runtime, one can significantly reduce memory consumption and deployment latency.

    $ conda create -n uform_torch python=3.10 -y
    $ conda create -n uform_onnx python=3.10 -y
    $ conda activate uform_torch && pip install -e ".[torch]" && conda deactivate
    $ conda activate uform_onnx && pip install -e ".[onnx]" && conda deactivate
    $ du -sh $(conda info --envs | grep 'uform_torch' | awk '{print $2}')
    > 5.2G    ~/conda/envs/uform_torch
    $ du -sh $(conda info --envs | grep 'uform_onnx' | awk '{print $2}')
    > 461M    ~/conda/envs/uform_onnx
    

    Most of that weight can be further reduced down to 100 MB for both the model and the runtime. You can pick one of many supported ONNX execution providers, which includes XNNPACK, CUDA and TensorRT for Nvidia GPUs, OpenVINO on Intel, DirectML on Windows, ROCm on AMD, CoreML on Apple devices, and more to come.

    Multimodal Chat in CLI

    The generative models can be used for chat-like experiences in the command line. For that, you can use the uform-chat CLI tool, which is available in the UForm package.

    $ pip install uform
    $ uform-chat --model unum-cloud/uform-gen2-dpo --image=zebra.jpg
    $ uform-chat --model unum-cloud/uform-gen2-dpo \
    >     --image="https://bit.ly/3tIVg9M" \
    >     --device="cuda:0" \
    >     --fp16