def __init__( self, shape, dtype, device=None, requires_grad=False, retain_grad=False, placement=None, sbp=None, is_consistent=False, is_lazy=False, data_initializer=None, ): if not isinstance(shape, oneflow_api.Size): if not isinstance(shape, tuple): shape = tuple(shape) shape = oneflow_api.Size(shape) data_initializer = (data_initializer if data_initializer is not None else flow.empty_initializer(dtype=dtype)) device = device if device is not None else oneflow_api.device("cpu") self.shape = shape self.dtype = dtype self.device = device self.requires_grad = requires_grad self.retain_grad = retain_grad self.placement = placement self.sbp = sbp self.is_consistent = is_consistent self.is_lazy = is_lazy self.data_initializer = data_initializer
def __init__( self, shape, dtype, device=None, requires_grad=False, retain_grad=False, placement=None, sbp=None, is_consistent=False, is_lazy=False, determining_initializer=None, ): device = device if device is not None else oneflow_api.device("cpu", 0) self._local_or_consistent_tensor = None self._undetermined_tensor = UndeterminedTensor( shape, dtype, device=device, requires_grad=requires_grad, retain_grad=retain_grad, placement=placement, sbp=sbp, is_consistent=is_consistent, is_lazy=is_lazy, ) if determining_initializer is None: determining_initializer = _default_initializer_for_determining self._determining_initializer = determining_initializer
def __init__( self, *args, dtype=None, device=None, requires_grad=False, retain_grad=False, placement=None, sbp=None, is_consistent=False, is_lazy=False, data_initializer=None, determining_initializer=None, ): assert len(args) > 0 dtype = dtype if dtype is not None else oneflow_api.float32 if placement is None: device = device if device is not None else oneflow_api.device( "cpu") if _input_args_is_tensor(*args): TODO() # liyurui, construct using another tensor elif _input_args_is_consistent_or_local(*args): self._local_or_consistent_tensor = args[0] self._undetermined_tensor = None elif _input_args_is_data(*args): self._local_or_consistent_tensor = None self._construct_with_data( *args, dtype=dtype, device=device, requires_grad=requires_grad, retain_grad=retain_grad, placement=placement, sbp=sbp, is_consistent=is_consistent, is_lazy=is_lazy, ) elif _input_args_is_shape(*args): shape = args self._local_or_consistent_tensor = None self._undetermined_tensor = UndeterminedTensor( shape, dtype, device=device, requires_grad=requires_grad, retain_grad=retain_grad, placement=placement, sbp=sbp, is_consistent=is_consistent, is_lazy=is_lazy, data_initializer=data_initializer, ) if determining_initializer is None: determining_initializer = _default_initializer_for_determining self._determining_initializer = determining_initializer else: # Maybe some other arguments to be supported, reported as error for now raise TypeError( "new() received an invalid combination of arguments")
def __init__(self, *args, dtype=None, device=None, requires_grad=False, retain_grad=False, placement=None, sbp=None, is_consistent=False, is_lazy=False, data_initializer=None, determining_initializer=None): assert len(args) > 0 dtype = dtype if dtype is not None else oneflow_api.float32 device = device if device is not None else oneflow_api.device("cpu") if _input_args_is_other_data(*args): self._immediately_construct( *args, dtype=dtype, device=device, requires_grad=requires_grad, retain_grad=retain_grad, is_lazy=is_lazy, ) elif _input_args_is_shape(*args): shape = args self._local_or_consistent_tensor = None # TODO(jianhao): update checkpoint to remove this attr self._variable_name = None self._undetermined_tensor = UndeterminedTensor( shape, dtype, device=device, requires_grad=requires_grad, retain_grad=retain_grad, placement=placement, sbp=sbp, is_consistent=is_consistent, is_lazy=is_lazy, data_initializer=data_initializer, ) if determining_initializer is None: determining_initializer = _default_initializer_for_determining self._determining_initializer = determining_initializer else: # Maybe some other arguments to be supported, reported as error for now raise TypeError( "new() received an invalid combination of arguments")