Parameter registration: Why could the layers in list be missing

Placing several layers into normal list, forward caller one by one is likely to succeed.

• 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

  • Check the parameters of Module
  • Track the optimist reference after replacement parameters

Suggested first

  • Python Basic Syntax:
  • Thick shape with Index

Python can be called, not Module can be managed

Placing several layers into normal list, forward caller one by one is likely to succeed. However, the parameters of Module, the equipment migration and the state_dict depend on the registration structure and do not automatically acquire all the regulatory semantics because the arbitrary Python container is fitted to the layers. The appropriate registration container should be used, or the object should be clearly registered as a submodule.

Sets two linear layers with the right to weigh w 1 = 1, w 2 = 2, and the model adds two layers in front. You get nine for input 3. Even if one of the layers is not registered, this number may be entirely correct; The problem does not arise until you have a view of the list of parameters, the mobile device or the heavy load model. The forward return is insufficient and the management entrance needs to be checked.

ModuleList to retain an iterative submodule, and ParameterList for the argument collection, which is not a decorative alias for any list. Sequential also provides for usual serial calls; If the actual branch structure is not a chain, the connection cannot be altered by error for registration purposes alone. Registration and calculation charts are separate functions.

Optimizer normally holds references to the parameter object that you have been creating. If model. weight is subsequently replaced with a new Parameter, the original optimizer does not necessarily follow the new object automatically. The new parameter appears in named_parameters and does not prove that it has entered the optimist parameter group. The optimizer needs to be created or updated by interface after the structure is determined.

Conversely, unregistered subjects may still be trained if they are handed over to a custom optimist in a user ' s face; It is therefore not accurate to say that “it is absolutely impossible to update without registration”. The danger is that it bypasses the conventional model management contract, that the preservation, equipment and parameter groups may not be consistent and that maintenance can easily be left out.

The normal Python list can save sublayer objects but does not equal to the registration of all layers under the Module container rules. Parameter discovery, equipment migration and sequencing depend on object management protocols rather than whether names are visible in the list. Minimum acceptance should list the parameter names, shape, object identity and optimizer members, and then make a fixed input comparison to save the load. The use of different weights prevents leakages from being masked by default values.

Structural reconstruction and weight loading should be verified separately, and both missing and redundant keys need to be clearly explained.

Output nine is correct. Can you prove that both levels are registered?

No, Python is different from the Module registered. The parameters and status list are checked.

Do old optimisers always update the weights after replacing them?

Not necessarily, it may still refer to old objects. Parameter groups should be clearly re-constructed or updated and the state of the optimizer checked.

Sources and reconciliations

Definitions, methods and interfaces are available.

  1. PyTorch — Building Models
  2. PyTorch — What is a state_dict

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.