Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: diffuseR
Title: Functional Interface to Diffusion Models in R
Version: 0.1.0.7
Version: 0.1.0.8
Authors@R: c(
person("Troy", "Hernandez", email = "troy@cornball.ai", role = c("aut", "cre"),
comment = c(ORCID = "0009-0005-4248-604X")),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# diffuseR 0.1.0.8 (development)

* The Qwen3 encoder builds its additive attention mask in the query
dtype, fixing the "invalid dtype for bias" CUDA error every FLUX.2
prompt encode hit through the fused SDPA path (since #33).

# diffuseR 0.1.0.7 (development)

## SDXL native pipeline from safetensors
Expand Down
15 changes: 10 additions & 5 deletions R/qwen3_text_encoder.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,22 @@ qwen3_encoder <- torch::nn_module(
b <- input_ids$shape[1]
s <- input_ids$shape[2]
device <- x$device
f32 <- torch::torch_float32()
dt <- x$dtype

rope <- .qwen3_rope_tables(s, self$head_dim, self$rope_theta, device)

# Additive causal (+ padding) mask [B, 1, S, S] in float32
neg <- -3.4e38
causal <- torch::torch_full(c(s, s), neg, dtype = f32,
# Additive causal (+ padding) mask [B, 1, S, S] in the compute dtype:
# the fused SDPA kernel requires the bias dtype to match the query.
# -10000 (the dit_ltx23 convention) stays finite in every float
# dtype, including where -3.4e38 would overflow bfloat16 to -Inf.
# The $neg()$add(1) chain (not `1 - x`) keeps torch Scalars, since
# the Ops dispatch materializes R scalars as Float and promotes.
neg <- -10000
causal <- torch::torch_full(c(s, s), neg, dtype = dt,
device = device)$triu(diagonal = 1L)
mask <- causal$unsqueeze(1L)$unsqueeze(1L)$expand(c(b, 1L, s, s))
if (!is.null(attention_mask)) {
pad <- (1 - attention_mask$to(dtype = f32, device = device))$mul(neg)
pad <- attention_mask$to(dtype = dt, device = device)$neg()$add(1)$mul(neg)
mask <- mask + pad$unsqueeze(2L)$unsqueeze(2L)
}

Expand Down
Loading