Code Monkey home page Code Monkey logo

Comments (3)

raymond-w-ko avatar raymond-w-ko commented on July 19, 2024 1

Hello, I was able to port the MNIST example from pytorch/examples successfully.
I was probably able to avoid the decref issue by making the class a root namespace definition.
The code is here: https://github.com/raymond-w-ko/techniko/blob/mnist/src/techniko/mnist.clj
The repo is here: https://github.com/raymond-w-ko/techniko/tree/mnist
I also added some instructions so hopefully it can serve as a full example on how to use pytorch to train a model in Clojure.

One issue I experienced is that I had to use a stack-resource-context to ensure GC is done at the end of a train or test batch loop, otherwise my GPU would quickly run out of VRAM. If you look at https://github.com/raymond-w-ko/techniko/blob/mnist/src/techniko/mnist.clj#L173 it gets tricky, because pytorch wants you to use a python with on torch.no_grad to internally disable gradient calculation (original example here: https://github.com/pytorch/examples/blob/master/mnist/main.py#L55).

If the test loop is replaced with any of the commented out code blocks, I get a cryptic python error in flight.

I can understand the first example throwing, since you are doing a double GIL lock since py/with does a GIL lock.

I do not understand why the second example throws since I didn't have time to deeply dive into the code.

from libpython-clj.

raymond-w-ko avatar raymond-w-ko commented on July 19, 2024

Sorry for the noise, I just saw the tests, which has the py/create-class fn. This should be enough for me to figure it out.

from libpython-clj.

cnuernber avatar cnuernber commented on July 19, 2024

Let me know how that goes, no one has tried that yet. When we bridge containers into python, we do subclass the appropriate abc classes, however, so it is lightly tested but as with anything in python we don't know how well we are really doing it. I will say that you want to be careful to ensure your objects don't go out of scope else you may find a decref call ruining your day.

from libpython-clj.

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.