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

Method kind

torchgen/model.py:1499–1538  ·  view source on GitHub ↗

What kind of schema is this? A functional schema is one that returns a newly allocated output; an inplace schema modifies the self argument inplace; an out schema writes the result into an explicitly provided out argument.

(self)

Source from the content-addressed store, hash-verified

1497 return bool(self.arguments.out)
1498
1499 def kind(self) -> SchemaKind:
1500 """
1501 What kind of schema is this? A functional schema is one
1502 that returns a newly allocated output; an inplace schema
1503 modifies the self argument inplace; an out schema writes
1504 the result into an explicitly provided out argument.
1505 """
1506 is_out = bool(self.arguments.out)
1507 is_scratch = bool(
1508 [arg for arg in self.arguments.out if arg.name.startswith("_scratch_")]
1509 )
1510 is_inplace = self.name.name.inplace
1511 is_mutable = any(
1512 a.annotation is not None and a.annotation.is_write
1513 for a in self.arguments.post_self_positional
1514 )
1515 assert not (is_out and is_inplace)
1516 # out= and inplace schemas can also have post_self_positional mutable args,
1517 # but we give precedence to out= and inplace when deciding the schema kind.
1518 # Tradeoff: we probably don't want to have to teach codegen that looks at inplace ops
1519 # to also worry about mutable post_self_positional arguments,
1520 # but it seems like a much bigger lift to classify them has having a new schema kind.
1521 # The number of ops that fit in this strange category is small enough that
1522 # we can probably manually write code for them instead of forcing the codegen to handle them.
1523 if is_inplace:
1524 return SchemaKind.inplace
1525 elif is_scratch:
1526 assert (
1527 is_out
1528 ), "invariant: all scratch operators are expected to be out= operators too"
1529 return SchemaKind.scratch
1530 elif is_out:
1531 assert (
1532 not is_scratch
1533 ), "We should not categorize a scratch op as an out variant. Check if the order of if statements are expected!"
1534 return SchemaKind.out
1535 elif is_mutable:
1536 return SchemaKind.mutable
1537 else:
1538 return SchemaKind.functional
1539
1540 # For every return:
1541 # - If the return aliases an input, we return the input name

Callers 15

__post_init__Method · 0.95
modifies_argumentsMethod · 0.95
gen_vmap_plumbingFunction · 0.45
self_to_out_signatureFunction · 0.45
mutable_to_out_signatureFunction · 0.45
generate_functionFunction · 0.45

Calls 1

anyFunction · 0.50

Tested by

no test coverage detected