1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// RLX — versatile ML compiler + runtime.
// Copyright (C) 2026 Eugene Hauptmann, Nataliya Kosmyna.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! FLUX.2 text encoder HIR on wgpu ([`Device::Gpu`], `gpu` feature).
#[cfg(feature = "gpu")]
use rlx_models::flux2::TINY_TEXT_ENCODER_LAYERS;
#[cfg(feature = "gpu")]
use rlx_models::flux2::{
compile_flux2_text_encoder_hir, synthetic_text_encoder_weights, tiny_text_encoder_config,
};
#[cfg(feature = "gpu")]
use rlx_runtime::Device;
#[cfg(feature = "gpu")]
#[test]
fn text_encoder_tiny_runs_on_wgpu() {
if !rlx_runtime::is_available(Device::Gpu) {
eprintln!("skip: wgpu (Device::Gpu) not available");
return;
}
let cfg = tiny_text_encoder_config();
let w = synthetic_text_encoder_weights(&cfg);
let batch = 1usize;
let seq = 4usize;
let ids_f32: Vec<f32> = (0..seq as u32).map(|x| x as f32).collect();
let (mut compiled, _) = compile_flux2_text_encoder_hir(
&cfg,
&w,
batch,
seq,
TINY_TEXT_ENCODER_LAYERS,
Device::Gpu,
None,
)
.unwrap();
let out = compiled.run(&[("input_ids", ids_f32.as_slice())]).remove(0);
let joint = cfg.hidden_size * TINY_TEXT_ENCODER_LAYERS.len();
assert_eq!(out.len(), batch * seq * joint);
}