Feature Extraction
Transformers
Safetensors
udream_bi_encoder
udream
text-encoder
bidirectional
Mixture of Experts
mixture-of-experts
ukrainian
text-to-image
diffusion
multilingual
custom_code
Instructions to use UDream/UDream-1.0-Bi-Encode with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use UDream/UDream-1.0-Bi-Encode with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="UDream/UDream-1.0-Bi-Encode", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("UDream/UDream-1.0-Bi-Encode", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
|
Download README.md from UDream/UDream-1.0-Bi-Encode: direct link, hf CLI and curl.
- Browser
- Download file 8.64 kB
-
https://huggingface.co/UDream/UDream-1.0-Bi-Encode/resolve/main/README.md
- Command line
-
hf download hf://UDream/UDream-1.0-Bi-Encode/README.md
-
curl -L -o README.md https://huggingface.co/UDream/UDream-1.0-Bi-Encode/resolve/main/README.md
8.64 kB
| license: apache-2.0 | |
| language: | |
| - uk | |
| - en | |
| - ru | |
| - pl | |
| - cs | |
| - be | |
| library_name: transformers | |
| pipeline_tag: feature-extraction | |
| base_model: UDream/UDream-1.0-Base | |
| tags: | |
| - udream | |
| - text-encoder | |
| - bidirectional | |
| - moe | |
| - mixture-of-experts | |
| - ukrainian | |
| - text-to-image | |
| - diffusion | |
| - multilingual | |
| - custom_code | |
| # UDream 1.0 Bi-Encode (`UDream/UDream-1.0-Bi-Encode`) | |
| **UDream 1.0 Bi-Encode** is an Apache 2.0, Ukrainian-first **bidirectional sparse Mixture-of-Experts (MoE) text encoder** (**4.14B total / 1.44B active parameters**, `d_model=2048`, **~8.6 GB VRAM** in `bf16`), adapted from [`UDream/UDream-1.0-Base`](https://huggingface.co/UDream/UDream-1.0-Base) specifically for **text-to-image (DiT / Flow Matching) conditioning** and **bilingual Ukrainian ↔ English semantic representations**. | |
| In a controlled 7-encoder downstream text-to-image benchmark (`Photon-Small 433M`, identical 100k MONET EN + 1k Ukrainian signage dataset, 8,000 steps), `UDream-1.0-Bi-Encode`: | |
| - **Outperformed all tested Apache 2.0 / causal 4B encoders** (`Qwen3.5-4B-Base`, `Gemma-4-E4B` Base, `Gemma-4-E4B-it`, causal `UDream-1.0-Base`, `UDream-1.0-SFT`) even on **held-out pure English validation** (`val_cond`, `cond_gain`, `cond_gain85`), | |
| - Achieved **#1 overall zero-shot Ukrainian → English T2I transfer (`ua_en_img_cos = 0.8245`)** across all 7 tested models (including `T5Gemma-2-4B`), | |
| - Eliminated channel outliers to **`top1_energy = 2.60%`** (`penult`) / **`3.99%`** (`last`) with **`100.0%` raw (un-normalized) EN ↔ UA Top-1 retrieval** and **25% fewer Ukrainian tokens** than Gemma 4 / Qwen 3.5. | |
| --- | |
| ## Architecture & Adaptation Recipe | |
| | Property | Specification | | |
| |---|---| | |
| | Base Checkpoint | [`UDream/UDream-1.0-Base`](https://huggingface.co/UDream/UDream-1.0-Base) (pretrained on 63.73B tokens) | | |
| | Architecture | Encoder-only Bidirectional Sparse MoE (`UDreamBiEncoderModel`, `is_causal=False`) | | |
| | Parameters (Total / Active) | **4.14B / 1.44B** backbone (`d_model=2048`, 26 layers: 4 dense + 22 MoE, 32 routed `top_k=6` + 1 shared) | | |
| | Hybrid Bidirectional Attention | 22 local sliding-window layers (`window=512`, RoPE `10k`) + 4 global **NoPE** layers (`5, 11, 17, 23`) | | |
| | Inference Footprint | **~8.6 GB VRAM** (`bf16`), `~1.8 ms/prompt` (RTX 5090), exact padding invariance (`fp32 cos=1.000000`) | | |
| | Tokenizer | `udream-64k` ByteLevel BPE (`vocab_size=64,128`, ~20.9 tok/prompt UA vs 26.1 Gemma 4 / 27.4 Qwen 3.5) | | |
| | Bidirectional Adaptation | 3,000 steps on 1× RTX 5090 (~1.7h): **744M** full-rank FP32 params (all 26 Attention, 4 Dense FFN, 22 Shared experts, 22 MoE routers, RMSNorm/FiLM); **3.46B** routed experts + token embeddings frozen in `bf16` to preserve world & Ukrainian knowledge | | |
| | Adaptation Objectives | Joint **Span-MLM (65%) + MNTP (35%)** (25% geometric spans 1..4; 49.2M tokens across EN prose, UA prose, and visual captions) + **Symmetric EN ↔ UA InfoNCE** (144k parallel pairs on both `(-4,-3,-2)` and `-1`) | | |
| --- | |
| ## Quickstart (`transformers`) | |
| Pass `trust_remote_code=True`. During training, every prompt starts with `<doc>` (id `4`) at position 0, which is stripped on output so 100% of prompt words are kept. The built-in `.encode()` helper handles this automatically. | |
| ### 1. Token-level states for Text-to-Image (DiT / Flow Matching) | |
| ```python | |
| import torch | |
| from transformers import AutoModel, AutoTokenizer | |
| repo_id = "UDream/UDream-1.0-Bi-Encode" | |
| tok = AutoTokenizer.from_pretrained(repo_id, trust_remote_code=True) | |
| enc = AutoModel.from_pretrained( | |
| repo_id, | |
| trust_remote_code=True, | |
| dtype=torch.bfloat16, | |
| device_map="cuda", | |
| ).eval() | |
| prompts = [ | |
| "a cozy wooden cabin in a snowy pine forest at golden hour, film grain", | |
| "затишна дерев'яна хатина в засніженому сосновому лісі на заході сонця, зерно плівки", | |
| ] | |
| # Recommended for T2I DiT conditioning: average of final-normed layers (-4, -3, -2) | |
| hidden, mask = enc.encode(prompts, tok, max_length=128, layers=(-4, -3, -2)) | |
| print(hidden.shape, mask.shape) # torch.Size([2, L, 2048]) torch.Size([2, L]) | |
| ``` | |
| ### 2. Bilingual EN ↔ UA Semantic Embeddings | |
| ```python | |
| emb = enc.encode(prompts, tok, max_length=128, layers=(-1,), pool="mean") | |
| print("EN <-> UA cosine similarity:", float((emb[0] * emb[1]).sum())) | |
| ``` | |
| ### 3. Standard Hugging Face `forward()` API | |
| ```python | |
| ids = tok("<doc>" + prompts[0], return_tensors="pt", add_special_tokens=False).to(enc.device) | |
| with torch.inference_mode(): | |
| out = enc(**ids, output_hidden_states=True) | |
| # out.last_hidden_state[:, 1:, :] -> [1, L, 2048] (stripping <doc>) | |
| ``` | |
| --- | |
| ## Benchmarks | |
| ### 1. Text Encoder X-Ray (16 parallel EN ↔ UA visual scene pairs, `bf16`) | |
| | Encoder | License | `dim` | VRAM (GB) | UA tok/prompt | `top1_energy` ↓ | `raw_ua_en_top1` ↑ | `z_ua_en_pair_cos` ↑ | `z_ua_en_margin` ↑ | `z_ua_en_top1` ↑ | | |
| |---|---|---:|---:|---:|---:|---:|---:|---:|---:| | |
| | **`UDream-1.0-Bi-Encode` (`-4,-3,-2`)** | **Apache 2.0** | 2048 | **8.60** | **20.9** | **2.60%** | **100.0%** | **+0.7095** | **+0.7767** | **100.0%** | | |
| | **`UDream-1.0-Bi-Encode` (`-1`)** | **Apache 2.0** | 2048 | **8.60** | **20.9** | **3.99%** | **100.0%** | **+0.7242** | **+0.7880** | **100.0%** | | |
| | `UDream-1.0-Base` (causal) | Apache 2.0 | 2048 | 8.60 | 20.9 | 7.61% | 93.8% | +0.4783 | +0.5919 | 100.0% | | |
| | `T5Gemma-2-4B` (`-1`, bidirectional) | Gemma ToU | 2560 | 8.17 | 26.1 | 34.46% | 96.9% | +0.3075 | +0.5230 | 100.0% | | |
| | `Qwen3.5-4B-Base` | Apache 2.0 | 2560 | 9.89 | 27.4 | 9.31% | 56.3% | +0.0010 | +0.3150 | 100.0% | | |
| | `Gemma-4-E2B` (Base) | Apache 2.0 | 1536 | 9.62 | 26.1 | 55.55% | 28.1% | -0.0772 | +0.2710 | 100.0% | | |
| | `Gemma-4-E4B` (Base) | Apache 2.0 | 2560 | 15.44 | 26.1 | 13.70% | 21.9% | -0.2542 | +0.2234 | 100.0% | | |
| | `Qwen3-4B` | Apache 2.0 | 2560 | 8.65 | 36.8 | 87.20% | 6.3% | — | +0.2180 | 75.0% | | |
| | `Gemma-4-E4B-it` | Apache 2.0 | 2560 | 15.43 | 26.1 | 89.95% | 21.9% | -0.2130 | +0.1041 | 53.1% | | |
| ### 2. Downstream Text-to-Image DiT Shootout (8,000 steps, `Photon-Small 433M`) | |
| All 7 frozen encoders trained identical `Photon-Small (433M)` DiT models (`bs=64`, `lr=2e-4`, `SPRINT keep=0.25`, `seed=0`) on the exact same 100k EN MONET + 1k UA signage dataset, evaluated on a strictly held-out EN MONET validation chunk (`val_cond`, `cond_gain = val_uncond - val_cond`, high-noise `t=0.85` `cond_gain85`) and zero-shot Ukrainian ↔ English image latent cosine similarity (`ua_en_img_cos`): | |
| | Rank | Frozen Text Encoder | Attention / License | `val_cond` ↓ (EN) | `cond_gain` ↑ (EN) | `val_cond85` ↓ | `cond_gain85` ↑ | Zero-shot UA `early` / `best` ↑ | | |
| |---:|---|---|---:|---:|---:|---:|---:| | |
| | 1 | `T5Gemma-2-4B` (`-1`) | Bidirectional / Gemma ToU | **0.83375** | **+0.00720** | **0.77627** | **+0.00685** | 0.699 / 0.741 | | |
| | **2 (#1 Apache 2.0)** | **`UDream-1.0-Bi-Encode` (`-4,-3,-2`)** | **Bidirectional / Apache 2.0** | **0.83502** | **+0.00546** | **0.77795** | **+0.00516** | **0.814 / 0.825** | | |
| | 3 | `Qwen3.5-4B-Base` | Causal hybrid / Apache 2.0 | 0.83522 | +0.00532 | 0.77800 | +0.00465 | 0.660 / 0.705 | | |
| | 4 | `Gemma-4-E4B` (Base) | Causal / Apache 2.0 | 0.83578 | +0.00490 | 0.77862 | +0.00479 | 0.359 / 0.422 | | |
| | 5 | `UDream-1.0-SFT` | Causal / Apache 2.0 | 0.83591 | +0.00487 | 0.77839 | +0.00452 | 0.720 / 0.753 | | |
| | 6 | `UDream-1.0-Base` | Causal / Apache 2.0 | 0.83614 | +0.00490 | 0.77845 | +0.00469 | 0.804 / 0.817 | | |
| | 7 | `Gemma-4-E4B-it` | Causal / Apache 2.0 | 0.83629 | +0.00381 | 0.77881 | +0.00346 | 0.578 / 0.626 | | |
| --- | |
| ## Limitations | |
| - **Encoder-only:** `UDream-1.0-Bi-Encode` removes the LM head and uses bidirectional attention (`is_causal=False`); it is not meant for autoregressive text generation (use [`UDream/UDream-1.0-Base`](https://huggingface.co/UDream/UDream-1.0-Base) for generation). | |
| - **Optimal sequence length:** Adaptation was performed at `seq_len=256` (within the 512-token local sliding window) targeting T2I prompts and sentence/paragraph embeddings; long-document retrieval beyond 512 tokens has not been benchmarked. | |
| - **MoE `bf16` rounding:** Because 22 layers use discrete `top_k=6/32` MoE routing, `bf16` batch-size GEMM rounding can occasionally flip a borderline expert (`cos ≈ 0.997` between single and padded batch; `fp32` is exact at `cos = 1.000000`, `max_diff = 5e-5`). | |
| --- | |
| ## Citation | |
| ```bibtex | |
| @misc{dormidontov2026udream10bi, | |
| title = {UDream 1.0 Bi-Encode: A Bidirectional Ukrainian-First Sparse MoE Text Encoder for Diffusion and Cross-Lingual Representations}, | |
| author = {Dormidontov, Oleksandr}, | |
| year = {2026}, | |
| url = {https://udream.com.ua} | |
| } | |
| ``` | |