code: def create_masks(
      input_size,
      hidden_size,
      n_hidden,
      input_order="sequential",
      input_degrees=None,
  ):
      # MADE paper sec 4:
      # degrees of connections between layers -- ensure at most in_degree - 1 connections
      degrees = []
  
      # set input degrees to what is provided in args (the flipped order of the previous layer in a stack of mades);
      # else init input degrees based on strategy in input_order (sequential or random)
      if input_order == "sequential":
          degrees += (
              [torch.arange(input_size)]
              if input_degrees is None
              else [input_degrees]
          )
          for _ in range(n_hidden + 1):
              degrees += [torch.arange(hidden_size) % (input_size - 1)]
          degrees += (
              [torch.arange(input_size) % input_size - 1]
              if input_degrees is None
              else [input_degrees % input_size - 1]
          )
  
      elif input_order == "random":
          degrees += (
              [torch.randperm(input_size)]
              if input_degrees is None
              else [input_degrees]
          )
          for _ in range(n_hidden + 1):
              min_prev_degree = min(
                  degrees[-1].min().item(), input_size - 1
              )
              degrees += [
                  torch.randint(
                      min_prev_degree, input_size, (hidden_size,)
                  )
              ]
          min_prev_degree = min(
              degrees[-1].min().item(), input_size - 1
          )
          degrees += (
              [
                  torch.randint(
                      min_prev_degree, input_size, (input_size,)
                  )
                  - 1
              ]
              if input_degrees is None
              else [input_degrees - 1]
          )
  
      # construct masks
      masks = []
      for d0, d1 in zip(degrees[:-1], degrees[1:]):
          masks += [(d1.unsqueeze(-1) >= d0.unsqueeze(0)).float()]
  
      return masks, degrees[0]
  
imports: import copy
  import math
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.distributions import Normal
label_desc: Use image node_id 1 for calling a global function with example usage: create_masks(input_size, hidden_size, n_hidden, input_order, input_degrees) and returns: masks,  degrees