Add option for Convolutions to operate over NTC and NHWC tensors #50962
Labels
feature
A request for a proper, new feature.
module: memory format
Memory format/layout related issues/changes (channels_last, nhwc)
triaged
This issue has been looked at a team member, and triaged and prioritized into an appropriate module
馃殌 Feature
nn.Conv1d
(and other convolutions) should have achannels_last: bool = False
: if true, then they operate over(N, L, C)
tensors -- otherwise they operate over(N, C, L)
arrays (the current default).Motivation
We work mainly with timeseries, where we want to mix convolutions with RNNs: right now, this is irritating, because most of the RNNs operate with channels-last (e.g.
batch, seq_len, channels
), while Conv1d operates with channel-first (batch, channels, seq_len
). This means that we have to add a bunch of transpositions to swap dimensions at the boundary between convolutions and RNNs.Ideally, there would be a way to tell
Conv1d
to operate over the samebatch, seq_len, channels
ordering as the RNNs do to avoid all of these unnecessary transposes.Pitch
nn.Conv1d
(and other convolutions) should have achannels_last: bool = False
: if true, then they operate over(N, L, C)
tensors -- otherwise they operate over(N, C, L)
arrays (the current default). There is some precedent for this kind of flag: the RNNs, for instance, have abatch_first
flag that switches between(seq_len, batch, channels)
to(batch, seq_len, channels)
operation.This would affect the semantics of the convolutions -- the dimensions here are what are returned by
tensor.shape
, not necessarily their internal memory layout as described in https://pytorch.org/tutorials/intermediate/memory_format_tutorial.html. Of course, perhaps the implementation of these convolutions could exploit some of the memory layout optimizations under-the-hood.cc @VitalyFedyunin @jamesr66a @ppwwyyxx
The text was updated successfully, but these errors were encountered: