Giter Club home page Giter Club logo

Comments (4)

LaurentMazare avatar LaurentMazare commented on September 21, 2024 3

Glad that you were able to track the issue down.
There are two ways to use no_grad with the rust bindings, either using no_grad with a closure:

    tch::no_grad(|| {
        // gradients are not tracked here
    });

Or using a no_grad_guard, in this cases gradient are not tracked until the guard reaches the end of its scope and is dropped.

{
    let guard = tch::no_grad_guard();
    // gradients are not tracked here
}

from tch-rs.

LaurentMazare avatar LaurentMazare commented on September 21, 2024

Would you have a repro for this ?
I just pushed a small example to try to replicate your issue. When running on gpu mode, my gpu memory stays constant a bit below 500MB. This is large but I think caused by pytorch internal caching, anyway I don't see the memory increasing.

As per your other questions:

  • The way to feed datasets depend a lot on how your dataset are structured. Reading files and then using of_slice should be reasonable. There are some helper functions in the vision module to help with image datasets.
  • Deallocation should be automatic when reaching the scope end (which is one of rust big advantage).
  • The memory consumption of forward_t depends a lot of what the model is doing. It can certainly double memory consumption and even more.

from tch-rs.

jerry73204 avatar jerry73204 commented on September 21, 2024

It turns out the overly large pre-fetch buffer exhausted the main memory. It's not tch's fault.
Besides, I find Torch forum suggests no_grad() to disable gradient engine. It helps reducing memory footprint.

from tch-rs.

jerry73204 avatar jerry73204 commented on September 21, 2024

Thanks for your reply. The thread can be closed.

from tch-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.