Git Product home page Git Product logo

Comments (6)

AlexeyKurakin avatar AlexeyKurakin commented on May 4, 2024

Hi,

For training on TPU, I would suggest you to look at https://github.com/google/objax/tree/master/examples/classify/img/imagenet which was initially written for TPU, but also works on multi-GPU system. In particular, take a look at train_op method and self.train_op_parallel attribute of Experiment class.

For TPU or multi-GPU system, one have to use objax.Parallel instead of Jit to parallelize and compile ops. Jit will also work, but Jit will run all ops on single GPU or single TPU core.

Also as you correctly noticed, Objax uses trick with temporary variables replacing module variables to make OOP paradigm work with functional core of JAX. This works completely transparent on any computational device and there is no need to write any other custom version of Jit.

Regarding running multiple training steps per single train call. The above mentioned example does not do it, nevertheless I found it's performance just a little slower compared to my other TF2 implementation which performs several steps per train call.
Note that I won't be providing specific performance numbers at right now, but we may consider doing more thorough benchmarking later.
Also we may add example which performs multiple training steps per train call later as well.

from objax.

AlexeyKurakin avatar AlexeyKurakin commented on May 4, 2024

So basically, if you're concerned about performance on TPU I would suggest to try existing examples with objax.Parallel. Likely performance will be satisfactory.

If you still need multiple training steps per single call of train op, we can consider adding such example later.

If you willing to contribute, feel free to add such example yourself. I suspect that adding regular for loop inside train_op may do the trick (i.e. it will be compiled to XLA while loop). However you need to figure out how to actually stream multiple batches of data into train_op

from objax.

AlexeyKurakin avatar AlexeyKurakin commented on May 4, 2024

Also, I briefly looked at other JAX libraries (Haiku and Flax). Seems like all of them alway perform single training step per train_op.
I suspect that either multiple training steps are unnecessary (i.e. don't provide any performance gains) or there are some issues with feeding multiple batches of data into single call of train_op compared to Tensorflow.

from objax.

AlexeyKurakin avatar AlexeyKurakin commented on May 4, 2024

I found example of how to perform multiple training steps per one call to train function: https://github.com/mlperf/training_results_v0.7/blob/3dbb53064a6b79354c68a6832414b6536fee1a75/Google/benchmarks/resnet/implementations/resnet-research-JAX-tpu-v3-8192/train.py#L603

It seems like it require to manually maintain infeed queue and manually write on-device while_loop which all looks cumbersome.
Given complexity of this setup, it makes sense to run benchmarks first before commiting to see how much performance we can gain from it.

from objax.

AlexeyKurakin avatar AlexeyKurakin commented on May 4, 2024

@kovasb is my explanation provided any clarity of the question?
Also would you be willing to do some prototyping / benchmarking of this change to see how useful it is for performance?

from objax.

AlexeyKurakin avatar AlexeyKurakin commented on May 4, 2024

I'll close this issue for now. If we figure out that there is a need to have multiple iterations per training loop, then I'll reopen it.

from objax.

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.