Git Product home page Git Product logo

Comments (2)

Maratyszcza avatar Maratyszcza commented on May 19, 2024

The difference between inference and output (forward pass in training) functions is based on two considerations:

  1. inference functions are optimized for batch = 1 case, while output functions are optimized for moderately large batch sizes (64 and above).
  2. While none of the following is currently implemented, I have plans to merge some extra operations into convolutional/fully connected layers. The type of operations which can be merged, depends on whether the framework would need to run backward pass on the layer using the outputs:
  • Both ReLU and ELU can be merged into the preceding convolutional (or fully connected) layer.
  • If the model is used for inference, 2x2 pooling with 2x2 stride can be merged into preceding convolutional or fully connected layer (potentially with embedded ReLU/ELU). If the layer is used for training, this fusion is impossible, because the backward pass on the convolutional layer would need the output of the convolutional layer before 2x2 pooling, which wouldn't be produced by the forward pass.
  • If the model is used for training, batch normalization layer can be partially merged into preceding convolutional or fully connected layer. Specifically, computation of per-channel mean values can be merged into the store stage of the preceding layer. In inference, batch normalization layer becomes a static scale + bias layer, and often can be statically merged into preceding convolutional or fully connected layer, so computation of per-channel mean activations makes no sense.

The reason why nnp_convolution_inference supports strides while nnp_convolution_output does not is that NNPACK is in active development and implicit_gemm algorithm and strided convolutions were implemented for inference function first. Support for implicit_gemm algorithm and strided convolutions in the training functions is in short-term plans, but for now you'd need to fall back to an implementation outside NNPACK.

One more clarification about implicit_gemm algorithm: it does not do patch2cols+sgemm, but rather does something smarter. High-performance implementations of SGEMM internally repack the matrix into cache-friendly form. Thus, a typical SGEMM-based implementation of a convolutional layer would involve two repacking operations: one inside patch2cols and another inside sgemm. NNPACK's implicit_gemm algorithm combines these two repacking operations into one; the main motivation is to operate with low memory overhead (NNPACK doesn't allocate memory for the whole patch2cols matrix, just for L3-sized block of it), but you'd likely find it performing better than traditional patch2cols+sgemm implementations due to fewer memory repacking operations.

from nnpack.

lironmo avatar lironmo commented on May 19, 2024

any update about the short term implementation, for stride size bigger than 1.

from nnpack.

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.