Skip to content

In-NMF Target Regularization ignored on GPU backend #75

Description

@clemenshug

Hi, first of all thank you for this amazing package! I was particularly happy about the extensive and extremely well written documentation accompanying the package.

I ran into an issue (I'm on commit df69ddd) where In-NMF Target Regularization via target_H appears to be ignored when run on a GPU. Here is an example from your docs, run using CPU and then GPU. The results using CPU are as expected, but on a GPU backend the result with or without target_H are virtually identical.

library(RcppML)
#> Loading required package: Matrix
#> 
#> Attaching package: 'RcppML'
#> The following object is masked from 'package:base':
#> 
#>     svd
data(hawaiibirds)
A <- hawaiibirds
meta <- attr(hawaiibirds, "metadata_h")
labels <- meta$island

gpu_available()
#> [1] TRUE

model_base_cpu <- nmf(A, k = 8, tol = 1e-4, maxit = 100, seed = 42, resource = "cpu")
T_mat_cpu <- compute_target(model_base_cpu@h, labels)
model_target_cpu <- nmf(A, k = 8, tol = 1e-4, maxit = 100, seed = 42, resource = "cpu",
                    target_H = T_mat_cpu, target_lambda = 0.10)

model_base_gpu <- nmf(A, k = 8, tol = 1e-4, maxit = 100, seed = 42, resource = "gpu")
T_mat_gpu <- compute_target(model_base_gpu@h, labels)
model_target_gpu <- nmf(A, k = 8, tol = 1e-4, maxit = 100, seed = 42, resource = "gpu",
                    target_H = T_mat_gpu, target_lambda = 0.10)

cat("CPU Target/Base MSE ratio:", model_target_cpu@misc$loss / model_base_cpu@misc$loss, "\n")
#> CPU Target/Base MSE ratio: 1.389043
cat("GPU Target/Base MSE ratio:", model_target_gpu@misc$loss / model_base_gpu@misc$loss, "\n")
#> GPU Target/Base MSE ratio: 0.9999993
max(abs(model_target_cpu@w - model_base_cpu@w))
#> [1] 0.1977129
max(abs(model_target_gpu@w - model_base_gpu@w))
#> [1] 8.940697e-08

Created on 2026-05-08 with reprex v2.1.1

Session info

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.5.2 (2025-10-31)
#>  os       Red Hat Enterprise Linux 9.7 (Plow)
#>  system   x86_64, linux-gnu
#>  ui       X11
#>  language (EN)
#>  collate  C.UTF-8
#>  ctype    C.UTF-8
#>  tz       America/New_York
#>  date     2026-05-08
#>  pandoc   3.9.0.2 @ /home/ch305/envs/r-reticulate/bin/ (via rmarkdown)
#>  quarto   NA
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cli           3.6.5   2025-04-23 [1] CRAN (R 4.5.2)
#>  digest        0.6.39  2025-11-19 [1] CRAN (R 4.5.2)
#>  evaluate      1.0.5   2025-08-27 [1] CRAN (R 4.5.2)
#>  fastmap       1.2.0   2024-05-15 [1] CRAN (R 4.5.2)
#>  fs            1.6.6   2025-04-12 [1] CRAN (R 4.5.2)
#>  glue          1.8.0   2024-09-30 [1] CRAN (R 4.5.2)
#>  htmltools     0.5.9   2025-12-04 [1] CRAN (R 4.5.2)
#>  knitr         1.51    2025-12-20 [1] CRAN (R 4.5.2)
#>  lattice       0.22-7  2025-04-02 [2] CRAN (R 4.5.2)
#>  lifecycle     1.0.5   2026-01-08 [1] CRAN (R 4.5.2)
#>  Matrix      * 1.7-4   2025-08-28 [2] CRAN (R 4.5.2)
#>  otel          0.2.0   2025-08-29 [1] CRAN (R 4.5.2)
#>  Rcpp          1.1.1   2026-01-10 [1] CRAN (R 4.5.2)
#>  RcppML      * 1.0.0   2026-04-24 [1] Github (zdebruine/RcppML@df69ddd)
#>  reprex        2.1.1   2024-07-06 [1] CRAN (R 4.5.2)
#>  rlang         1.1.7   2026-01-09 [1] CRAN (R 4.5.2)
#>  rmarkdown     2.30    2025-09-28 [1] CRAN (R 4.5.2)
#>  sessioninfo   1.2.3   2025-02-05 [1] CRAN (R 4.5.2)
#>  withr         3.0.2   2024-10-28 [1] CRAN (R 4.5.2)
#>  xfun          0.56    2026-01-18 [1] CRAN (R 4.5.2)
#>  yaml          2.3.12  2025-12-10 [1] CRAN (R 4.5.2)
#> 
#>  [1] /home/ch305/R/x86_64-pc-linux-gnu-library/4.5
#>  [2] /n/app/R/4.5.2-gcc-14.2.0/lib64/R/library
#>  * ── Packages attached to the search path.
#> 
#> ──────────────────────────────────────────────────────────────────────────────
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 570.144                Driver Version: 570.144        CUDA Version: 12.8     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  Tesla V100S-PCIE-32GB          On  |   00000000:3B:00.0 Off |                    0 |
| N/A   31C    P0             36W /  250W |     310MiB /  32768MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions