question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ChainerX needs to support more routines

See original GitHub issue

Update We’ve introduced an Op registration and dispatch mechanism. This practically means that Device methods will be replaced by Op implementations. E.g. Device::Arange -> ArangeOp : public Op. The following description will soon be updated to take this into account.

class FuncOp : public Op {
public:
    static const char* name() { return "Func"; }
    // Call is overridden per device. Does not create a graph but merely performs device computations such as calling a kernel in case of CUDA.
    // Call can have any signature.
    virtual void Call(..., const Array& out) = 0;  
    // Another definition would be
    // virtual Array Call(..., const nonstd::optional<Array>& out) = 0;  
};

class CudaFuncOp : public FuncOp {
// Override Call.
};

CHAINERX_REGISTER_OP_CUDA(FuncOp, CudaFuncOp);  // Allows backend.CallOp<FuncOp>(...);

Array Func(...) {  // A routine called `Func`.
    Array out = ....;
    {
        NoBackpropModeScope scope{};
        device.backend().CallOp<ArangeOp>(..., out);
    }
    // Create graph.
    return out;
}


The current repository of backpropable operations, or “routines” in ChainerX is still limited. We’d like to open this as a “contribution-welcome”-labeled issue for any contributor to introduce new routines and take part in the early development of ChainerX.

References

Implementing routines

What kinds of routines are missing?

Routines that need to be implemented probably fall into either of the following two categories.

  • NumPy compatible {numpy,chainerx} functions and {chainerx,numpy}.ndarray methods.
  • Deep learning routines such as convolutions, pooling, RNN-type routines, etc.

Please make sure that it’s not already implemented by checking the list of available routines.

How do you start implementing routines?

  1. Make sure you can build ChainerX. Instructions here.

  2. If you are unsure which routine to start working on, refer to this list or create an issue suggesting or asking for one. Some routines will require device implementation (for each backend, i.e. native and CUDA) while for some, it might be sufficient to use existing device methods. The latter is easier to work on but it might not be obvious at first which routine that applies to unless you know the implementation details beforehand and what device methods are already available (see list above).

  3. Implement the routine.

  • Check if the routine is temporarily made available via the NumPy/CuPy fallback mechanism. If it is, delete the fallback.
  • Declare a routine interface.
  • Define forward pass using device methods. If device methods are missing, implement them.
  • Define backward pass using chainerx::BackwardBuilder.
  • Declare the routine as a chainerx::Array method if appropriate.
  • Write Python bindings and tests using test utilities.

Getting familiar with the ChainerX code base

Here are some starting points.

To get familiar with the C++ code base.

Array (with autograd)

Routines

  • chainerx/routines : Defines “routines”, i.e. forward/backward operations on the Array such as taking the sum or applying a convolution.
  • chainerx::BackwardBuilder: Extends the computation graph and is used by routines.
  • chainerx::Device: A device interface with operations on arrays. The device interface is currently implemented by chainerx::native::NativeDevice and chainerx::cuda::CudaDevice. A routine delegates the actual computation to these devices. Note that these operations only operate on the raw data and should not involve any graph operations (this might change).
  • chainerx/native: Contains native implementations including chainerx::native::NativeDevice.
  • chainerx/cuda: Contains CUDA implementations including chainerx::cuda::CudaDevice.

Graph

  • chainerx::ArrayNode: A node representing an array in the computational graph. It is owned by an chainerx::ArrayBody.
  • chainerx::OpNode: A node representing an operation in the computational graph.

Other

  • chainerx::Context: Manages the runtime state. A context has backends, which have devices.
  • Units tests are written next to their source files being tested, i.e. chainerx/routines/logic.h is tested by chainerx/routines/logic_test.cc. You can take a look at the routine tests to see how arrays are used.
  • Python bindings are created with pybind11.
  • ChainerX C++ MNIST example.

Please note that the descriptions above may change as ChainerX is being developed.

Coding style

Please refer to https://github.com/chainer/chainer/issues/5778

Ongoing / Status

NOT UPDATED (since there are more PRs than expected and it’s difficult to maintain the status here)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:41 (35 by maintainers)

github_iconTop GitHub Comments

1reaction
hvycommented, Sep 24, 2019

Thanks for showing interest. Please take a look at the top description since it includes a link to a spreadsheet of routines and their statuses. You might want to check the source code before starting on one to really make sure that it hasn’t been implemented though.

1reaction
hvycommented, Apr 23, 2019

Just another heads up but we should to for each ChainerX routine that has a corresponding Chainer function (chainer.functions.*) also override forward_chainerx in that Chainer function. This should improve the performance of the Chainer function when used with ChainerX since fallback is avoided.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ChainerX Tutorial — Chainer 7.8.1 documentation
The module chainerx aims to support a NumPy compatible interface with additional operations specific to neural networks. It for instance provides chainerx.conv ...
Read more >
ChainerX routines (public) - Google Drive
A B C E F G H I J 1 Category Routine Priority Difficulty C++ Python Backprop FunctionNode 2 NumPy Creation identity Duplicate NA 3 NumPy...
Read more >
Chainer and ChainerX - Nvidia
Variables hold how they were computed. ... What is needed for modern deep learning frameworks? ... Being made faster and more portable with...
Read more >
Expand ChainerX Ops: Differentiable Linear Algebra
ChainerX is a versatile ndarray implementation with special support of deep learning-specific operations. Therefore, it is important to support many ...
Read more >
ChainerX and How to Take Part - SlideShare
... ChainerX needs to support more routines • A list of unimplemented routines https://github.com/chainer/chainer/issues/6423 contribution- ...
Read more >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found