mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: There is a module called `2to3` which you can target for future specifically to remove these, the directory of `caffe2` has the most redundant imports: ```2to3 -f future -w caffe2``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/45033 Reviewed By: seemethere Differential Revision: D23808648 Pulled By: bugra fbshipit-source-id: 38971900f0fe43ab44a9168e57f2307580d36a38
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
|
|
|
|
|
|
|
|
|
|
from caffe2.python import core
|
|
|
|
import numpy as np
|
|
|
|
|
|
class ParameterTags(object):
|
|
BIAS = 'BIAS'
|
|
WEIGHT = 'WEIGHT'
|
|
COMPUTED_PARAM = 'COMPUTED_PARAM'
|
|
|
|
|
|
class ParameterInfo(object):
|
|
|
|
def __init__(
|
|
self, param_id, param, key=None, shape=None, length=None,
|
|
grad=None, blob_copy=None):
|
|
assert isinstance(param, core.BlobReference)
|
|
self.param_id = param_id
|
|
self.name = str(param)
|
|
self.blob = param
|
|
self.key = key
|
|
self.shape = shape
|
|
self.size = None if shape is None else np.prod(shape)
|
|
self.length = max(1, length if length is not None else 1)
|
|
self.grad = grad
|
|
self._cloned_init_net = None
|
|
# Optionally store equivalent copies of the blob
|
|
# in different precisions (i.e. half and float copies)
|
|
# stored as a dict of TensorProto.DataType -> BlobReference
|
|
self.blob_copy = blob_copy
|
|
# each param_info can have its own optimizer. It can be set within
|
|
# OptimizerContext (caffe2/python/optimizer.py)
|
|
self._optimizer = None
|
|
|
|
@property
|
|
def parameter(self):
|
|
return self.blob
|
|
|
|
@property
|
|
def optimizer(self):
|
|
return self._optimizer
|
|
|
|
@optimizer.setter
|
|
def optimizer(self, value):
|
|
assert self._optimizer is None, "optimizer has already been set"
|
|
self._optimizer = value
|
|
|
|
def __str__(self):
|
|
return self.name
|