expand and repeat: Storage and writing boundaries behind the same values

Expanding a vector to multiple lines allows the same values to be obtained mathematically, while using different memory strategies.

• Step by stepCollate in 2 self-measured2 First-hand sources
Start Body
Learning objectives and first steps2 objectives 2 first fixes

Try to do it after reading

  • Compare stride view with actual repeat
  • Identify the in situ risk of shared location

Suggested first

  • Python Basic Syntax:
  • Thick shape with Index

Repeated displays do not necessarily require duplicate storage

Expanding a vector to multiple lines allows the same values to be obtained mathematically, while using different memory strategies. expand often provides viewing by setting an axis of 1 size to zero stride; repeat copies the data as requested. The two may be the same in the middle of a read-only direction, but cannot be understood interchangeably when it comes to in situ writing, memory and subsequent layout.

Take the original shape as a vector [2,3] [2,4,6] and expand it to [2,3]. Both rows show [2,4,6], but expand Axis 1 stride is 0, meaning that the same columns in both rows point to the same original element. The two lines generated by repeat can take different positions. The printing of two matrices does not show this difference.

If only line 0 of the second line of the results is to be expanded, there is a problem with multiple logical locations sharing one store. Some in situ operations may be rejected, while other direct indexing may also affect aliases; The results should not be treated as two independent and writeable data. When independent changes are required, a clear copy is selected.

Inversely, reuse still implies a cumulative contribution to the original input. If both lines of output are combined, the gradient of the original vector is 2 per item, not automatically turning into two separate sets of parameters because repeat is stored independently. Storage copying and calculating map parameters are shared at different levels, and the gradient cannot be judged solely for assigning new memory.

expand usually only increases the axle size of 1 and does not want to stretch any axle. For new peacekeeping pilot targets shape, the check should also be performed on API. Extended view is then sent to the calculation that requires continuous input, which may result in additional materialization, and whether savings still need to be measured along the entire path.

expand is stored with zero-step re-entry, and the same value corresponds to multiple logical locations. If the result is to be written in situ, it may not be consistent with the one-placed hypothesis, and it should be clearly copied and written to the need. The values of shape, stride, shared and modified can be checked in the real environment and the peak memory can be evaluated separately; Do not assume that the whole network will not be copied from one place.

(a) To view a duplicated location and the original vector at the same time as the debugging log, which can describe aliasing behaviour; However, do not make random in situ tests in normal training maps, so as not to destroy the old values needed to reverse them.

Zero stride Why do you show the second line?

This axis index is added without any change in the storage bias, and the same column reads the same element as the original one, so no need to save a separate line.

Will repeat add a gradient to the original input?

Yes, if these duplicate values are still entered from the same calculation chart, the contribution of all use paths is aggregated.

Sources and reconciliations

Definitions, methods and interfaces are available.

  1. PyTorch — Introduction to PyTorch Tensors
  2. torch.Tensor.expand

Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.

← Back to the knowledge directory
Ask Max Ask about this site
Ask Max ↗

Opening the assistant…

Paper figure

Photo comments

LEAVE A NOTE

About this photograph

Connecting to the discussion board…

    Comments become public after moderation. You can delete your own comments from this browser.
    No email is required. Clearing cookies prevents this browser from claiming earlier comments.

    MAX WANG / INDEX

    Find something

    Enter a keyword, or explore the directory below.