Close Menu
geekfence.comgeekfence.com
    What's Hot

    The AI Revolution and the Physical Internet

    June 19, 2026

    Five ways to do least squares (with torch)

    June 19, 2026

    Announcing Amazon EC2 G7 instances accelerated by NVIDIA RTX PRO 4500 Blackwell Server Edition GPUs

    June 19, 2026
    Facebook X (Twitter) Instagram
    • About Us
    • Contact Us
    Facebook Instagram
    geekfence.comgeekfence.com
    • Home
    • UK Tech News
    • AI
    • Big Data
    • Cyber Security
      • Cloud Computing
      • iOS Development
    • IoT
    • Mobile
    • Software
      • Software Development
      • Software Engineering
    • Technology
      • Green Technology
      • Nanotechnology
    • Telecom
    geekfence.comgeekfence.com
    Home»Artificial Intelligence»Posit AI Blog: torch 0.10.0
    Artificial Intelligence

    Posit AI Blog: torch 0.10.0

    AdminBy AdminMarch 17, 2026No Comments5 Mins Read7 Views
    Facebook Twitter Pinterest LinkedIn Telegram Tumblr Email
    Posit AI Blog: torch 0.10.0
    Share
    Facebook Twitter LinkedIn Pinterest Email


    We are happy to announce that torch v0.10.0 is now on CRAN. In this blog post we
    highlight some of the changes that have been introduced in this version. You can
    check the full changelog here.

    Automatic Mixed Precision

    Automatic Mixed Precision (AMP) is a technique that enables faster training of deep learning models, while maintaining model accuracy by using a combination of single-precision (FP32) and half-precision (FP16) floating-point formats.

    In order to use automatic mixed precision with torch, you will need to use the with_autocast
    context switcher to allow torch to use different implementations of operations that can run
    with half-precision. In general it’s also recommended to scale the loss function in order to
    preserve small gradients, as they get closer to zero in half-precision.

    Here’s a minimal example, ommiting the data generation process. You can find more information in the amp article.

    ...
    loss_fn <- nn_mse_loss()$cuda()
    net <- make_model(in_size, out_size, num_layers)
    opt <- optim_sgd(net$parameters, lr=0.1)
    scaler <- cuda_amp_grad_scaler()
    
    for (epoch in seq_len(epochs)) {
      for (i in seq_along(data)) {
        with_autocast(device_type = "cuda", {
          output <- net(data[[i]])
          loss <- loss_fn(output, targets[[i]])  
        })
        
        scaler$scale(loss)$backward()
        scaler$step(opt)
        scaler$update()
        opt$zero_grad()
      }
    }

    In this example, using mixed precision led to a speedup of around 40%. This speedup is
    even bigger if you are just running inference, i.e., don’t need to scale the loss.

    Pre-built binaries

    With pre-built binaries, installing torch gets a lot easier and faster, especially if
    you are on Linux and use the CUDA-enabled builds. The pre-built binaries include
    LibLantern and LibTorch, both external dependencies necessary to run torch. Additionally,
    if you install the CUDA-enabled builds, the CUDA and
    cuDNN libraries are already included..

    To install the pre-built binaries, you can use:

    options(timeout = 600) # increasing timeout is recommended since we will be downloading a 2GB file.
    kind <- "cu117" # "cpu", "cu117" are the only currently supported.
    version <- "0.10.0"
    options(repos = c(
      torch = sprintf("https://storage.googleapis.com/torch-lantern-builds/packages/%s/%s/", kind, version),
      CRAN = " # or any other from which you want to install the other R dependencies.
    ))
    install.packages("torch")

    As a nice example, you can get up and running with a GPU on Google Colaboratory in
    less than 3 minutes!

    Colaboratory running torch
    Colaboratory running torch

    Speedups

    Thanks to an issue opened by @egillax, we could find and fix a bug that caused
    torch functions returning a list of tensors to be very slow. The function in case
    was torch_split().

    This issue has been fixed in v0.10.0, and relying on this behavior should be much
    faster now. Here’s a minimal benchmark comparing both v0.9.1 with v0.10.0:

    bench::mark(
      torch::torch_split(1:100000, split_size = 10)
    )

    With v0.9.1 we get:

    # A tibble: 1 × 13
      expression      min  median `itr/sec` mem_alloc `gc/sec` n_itr  n_gc total_time
                       
    1 x             322ms   350ms      2.85     397MB     24.3     2    17      701ms
    # ℹ 4 more variables: result , memory , time , gc 

    while with v0.10.0:

    # A tibble: 1 × 13
      expression      min  median `itr/sec` mem_alloc `gc/sec` n_itr  n_gc total_time
                       
    1 x              12ms  12.8ms      65.7     120MB     8.96    22     3      335ms
    # ℹ 4 more variables: result , memory , time , gc 

    Build system refactoring

    The torch R package depends on LibLantern, a C interface to LibTorch. Lantern is part of
    the torch repository, but until v0.9.1 one would need to build LibLantern in a separate
    step before building the R package itself.

    This approach had several downsides, including:

    • Installing the package from GitHub was not reliable/reproducible, as you would depend
      on a transient pre-built binary.
    • Common devtools workflows like devtools::load_all() wouldn’t work, if the user didn’t build
      Lantern before, which made it harder to contribute to torch.

    From now on, building LibLantern is part of the R package-building workflow, and can be enabled
    by setting the BUILD_LANTERN=1 environment variable. It’s not enabled by default, because
    building Lantern requires cmake and other tools (specially if building the with GPU support),
    and using the pre-built binaries is preferable in those cases. With this environment variable set,
    users can run devtools::load_all() to locally build and test torch.

    This flag can also be used when installing torch dev versions from GitHub. If it’s set to 1,
    Lantern will be built from source instead of installing the pre-built binaries, which should lead
    to better reproducibility with development versions.

    Also, as part of these changes, we have improved the torch automatic installation process. It now has
    improved error messages to help debugging issues related to the installation. It’s also easier to customize
    using environment variables, see help(install_torch) for more information.

    Thank you to all contributors to the torch ecosystem. This work would not be possible without
    all the helpful issues opened, PRs you created and your hard work.

    If you are new to torch and want to learn more, we highly recommend the recently announced book ‘Deep Learning and Scientific Computing with R torch’.

    If you want to start contributing to torch, feel free to reach out on GitHub and see our contributing guide.

    The full changelog for this release can be found here.

    Enjoy this blog? Get notified of new posts by email:

    Posts also available at r-bloggers



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

    Related Posts

    Five ways to do least squares (with torch)

    June 19, 2026

    The Download: a new hunt for dark matter and Kenya’s case for going solar

    June 18, 2026

    The Case Against Building Your Own Agent Platform – O’Reilly

    June 17, 2026

    Research into how AI can help users understand skin conditions

    June 16, 2026

    5 foundations for reshaping the future of education and AI

    June 15, 2026

    Jinhua Zhao named head of the Department of Urban Studies and Planning | MIT News

    June 14, 2026
    Top Posts

    Understanding U-Net Architecture in Deep Learning

    November 25, 202555 Views

    Hard-braking events as indicators of road segment crash risk

    January 14, 202630 Views

    Redefining AI efficiency with extreme compression

    March 25, 202627 Views
    Don't Miss

    The AI Revolution and the Physical Internet

    June 19, 2026

    As we look at the massive AI boom sweeping across the globe, what does it…

    Five ways to do least squares (with torch)

    June 19, 2026

    Announcing Amazon EC2 G7 instances accelerated by NVIDIA RTX PRO 4500 Blackwell Server Edition GPUs

    June 19, 2026

    Inside Gentlemen’s EDR killer framework

    June 19, 2026
    Stay In Touch
    • Facebook
    • Instagram
    About Us

    At GeekFence, we are a team of tech-enthusiasts, industry watchers and content creators who believe that technology isn’t just about gadgets—it’s about how innovation transforms our lives, work and society. We’ve come together to build a place where readers, thinkers and industry insiders can converge to explore what’s next in tech.

    Our Picks

    The AI Revolution and the Physical Internet

    June 19, 2026

    Five ways to do least squares (with torch)

    June 19, 2026

    Subscribe to Updates

    Please enable JavaScript in your browser to complete this form.
    Loading
    • About Us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • Terms and Conditions
    © 2026 Geekfence.All Rigt Reserved.

    Type above and press Enter to search. Press Esc to cancel.