MCPcopy Create free account
hub / github.com/pytorch/pytorch / __init__

Method __init__

caffe2/python/layers/position_weighted.py:23–51  ·  view source on GitHub ↗
(self, model, input_record, weight_optim=None,
                 name="position_weights")

Source from the content-addressed store, hash-verified

21
22class PositionWeighted(ModelLayer):
23 def __init__(self, model, input_record, weight_optim=None,
24 name="position_weights"):
25 super().__init__(model, name, input_record)
26
27 assert isinstance(input_record, schema.List), "Incorrect input type"
28 length_metadata = input_record.lengths.metadata
29 max_length = (length_metadata.categorical_limit if length_metadata is
30 not None else None)
31 if max_length is not None:
32 self.shape = max_length
33 else:
34 self.shape = get_categorical_limit(input_record)
35 logger.warning(
36 '{}: categorical_limit of lengths is not available, using '
37 'categorical_limit of the keys: {}'.format(
38 str(input_record.lengths()), self.shape))
39
40 self.pos_w = self.create_param(param_name='pos_w',
41 shape=[self.shape, ],
42 initializer=('ConstantFill', {'value': 1.0}),
43 optimizer=weight_optim)
44
45 self.output_schema = schema.Struct(
46 ('position_weights',
47 schema.Scalar((np.float32, self.shape),
48 self.get_next_blob_reference("pos_w_gather")))
49 )
50
51 self.tags.update({Tags.HANDLE_AS_SPARSE_LAYER})
52
53 def get_memory_usage(self):
54 return self.shape

Callers

nothing calls this directly

Calls 8

get_categorical_limitFunction · 0.90
isinstanceFunction · 0.85
warningMethod · 0.80
lengthsMethod · 0.80
formatMethod · 0.45
create_paramMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected