(
self, block, desc, type=None, inputs=None, outputs=None, attrs=None
)
| 3295 | } |
| 3296 | |
| 3297 | def __init__( |
| 3298 | self, block, desc, type=None, inputs=None, outputs=None, attrs=None |
| 3299 | ): |
| 3300 | # read attr type index from op proto to avoid unexpected type |
| 3301 | # conversions, e.g. narrowing conversion like double to float |
| 3302 | try: |
| 3303 | proto = OpProtoHolder.instance().get_op_proto(type) |
| 3304 | self._attr_types = {} |
| 3305 | for attr in proto.attrs: |
| 3306 | self._attr_types[attr.name] = attr.type |
| 3307 | except ValueError: |
| 3308 | pass |
| 3309 | |
| 3310 | if in_dygraph_mode(): |
| 3311 | if type is None: |
| 3312 | raise ValueError( |
| 3313 | "`type` to initialized an Operator can not be None." |
| 3314 | ) |
| 3315 | self._type = type |
| 3316 | self.attrs = attrs if attrs else {} |
| 3317 | else: |
| 3318 | self.block = block |
| 3319 | self.desc = desc |
| 3320 | # note: not add self.attrs here: |
| 3321 | # https://github.com/PaddlePaddle/Paddle/pull/12583#pullrequestreview-145093173 |
| 3322 | op_attrs = attrs |
| 3323 | if op_attrs is None: |
| 3324 | op_attrs = {} |
| 3325 | del attrs |
| 3326 | |
| 3327 | # attr for static graph mode cuda graph |
| 3328 | self._cuda_graph_attr = _current_cuda_graph_mode |
| 3329 | |
| 3330 | # attr for OP AMP mode |
| 3331 | # using dynamic import to avoid cyclic dependency |
| 3332 | from paddle.static.amp.fp16_utils import DEFAULT_AMP_OPTIONS |
| 3333 | |
| 3334 | self._amp_options: AmpOptions = DEFAULT_AMP_OPTIONS |
| 3335 | |
| 3336 | # record the call path of op, only used in AutoParallel |
| 3337 | self._struct_name = _full_name_struct() |
| 3338 | |
| 3339 | op_maker = core.op_proto_and_checker_maker |
| 3340 | |
| 3341 | if op_maker.kOpRoleAttrName() not in op_attrs: |
| 3342 | op_attrs[op_maker.kOpRoleAttrName()] = ( |
| 3343 | self.block.program._op_role |
| 3344 | ) |
| 3345 | |
| 3346 | role_var_name = op_maker.kOpRoleVarAttrName() |
| 3347 | if ( |
| 3348 | len(self.block.program._op_role_var) != 0 |
| 3349 | and role_var_name not in op_attrs |
| 3350 | ): |
| 3351 | op_attrs[role_var_name] = self.block.program._op_role_var |
| 3352 | |
| 3353 | if role_var_name in op_attrs and len(op_attrs[role_var_name]) == 0: |
| 3354 | del op_attrs[role_var_name] |
nothing calls this directly
no test coverage detected