Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wux_labs
Tensorflow
提交
778dd23c
T
Tensorflow
项目概览
wux_labs
/
Tensorflow
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Tensorflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
778dd23c
编写于
9月 11, 2023
作者:
F
Faizan Muhammad
提交者:
TensorFlower Gardener
9月 11, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Prepare rename GenericFunction to PolymorphicFunction
PiperOrigin-RevId: 564434713
上级
6e2a4776
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
60 addition
and
27 deletion
+60
-27
tensorflow/python/eager/polymorphic_function/polymorphic_function.py
...python/eager/polymorphic_function/polymorphic_function.py
+18
-18
tensorflow/python/ops/cond.py
tensorflow/python/ops/cond.py
+2
-2
tensorflow/python/saved_model/signature_serialization.py
tensorflow/python/saved_model/signature_serialization.py
+1
-1
tensorflow/python/trackable/autotrackable.py
tensorflow/python/trackable/autotrackable.py
+1
-1
tensorflow/python/types/core.py
tensorflow/python/types/core.py
+9
-3
tensorflow/python/types/trace.py
tensorflow/python/types/trace.py
+2
-2
tensorflow/tools/api/golden/v2/tensorflow.__internal__.function.-function.pbtxt
...olden/v2/tensorflow.__internal__.function.-function.pbtxt
+1
-0
tensorflow/tools/api/golden/v2/tensorflow.types.experimental.-generic-function.pbtxt
.../v2/tensorflow.types.experimental.-generic-function.pbtxt
+1
-0
tensorflow/tools/api/golden/v2/tensorflow.types.experimental.-polymorphic-function.pbtxt
...tensorflow.types.experimental.-polymorphic-function.pbtxt
+21
-0
tensorflow/tools/api/golden/v2/tensorflow.types.experimental.pbtxt
...w/tools/api/golden/v2/tensorflow.types.experimental.pbtxt
+4
-0
未找到文件。
tensorflow/python/eager/polymorphic_function/polymorphic_function.py
浏览文件 @
778dd23c
...
...
@@ -448,10 +448,10 @@ class OptionalXlaContext:
self
.
xla_context
.
Exit
()
# TODO(
mdan): Consider expose this type for instance type checking
.
# TODO(
b/297237997): Use PolymorphicFunction here after migrating uses
.
@
tf_export
(
"__internal__.function.Function"
,
v1
=
[])
class
Function
(
core
.
GenericFunction
,
trackable
.
Trackable
):
"""A `tf.types.experimental.
Gener
icFunction` created by `tf.function`.
"""A `tf.types.experimental.
Polymorph
icFunction` created by `tf.function`.
Currently, individual methods/attributes under this class are not guaranteed
by the TF API contract, and are subject to future changes.
...
...
@@ -802,7 +802,7 @@ class Function(core.GenericFunction, trackable.Trackable):
@
traceback_utils
.
filter_traceback
def
__call__
(
self
,
*
args
,
**
kwds
):
# Implements
Gener
icFunction.__call__.
# Implements
Polymorph
icFunction.__call__.
if
self
.
_run_functions_eagerly
:
with
trace
.
Trace
(
self
.
_name
,
tf_function_call
=
"eager"
):
return
self
.
_python_function
(
*
args
,
**
kwds
)
...
...
@@ -954,7 +954,7 @@ class Function(core.GenericFunction, trackable.Trackable):
)
def
experimental_get_compiler_ir
(
self
,
*
args
,
**
kwargs
):
# Implements
Gener
icFunction.experimental_get_compiler_ir
# Implements
Polymorph
icFunction.experimental_get_compiler_ir
context
.
ensure_initialized
()
if
not
self
.
_jit_compile
:
raise
ValueError
(
"Compiler IR can only be returned for functions marked "
...
...
@@ -1222,7 +1222,7 @@ class Function(core.GenericFunction, trackable.Trackable):
return
concrete
def
get_concrete_function
(
self
,
*
args
,
**
kwargs
):
# Implements
Gener
icFunction.get_concrete_function.
# Implements
Polymorph
icFunction.get_concrete_function.
concrete
=
self
.
_get_concrete_function_garbage_collected
(
*
args
,
**
kwargs
)
concrete
.
_garbage_collector
.
release
()
# pylint: disable=protected-access
return
concrete
...
...
@@ -1295,10 +1295,10 @@ def function(
experimental_relax_shapes
=
None
,
experimental_compile
=
None
,
experimental_follow_type_hints
=
None
# pylint: disable=unused-argument
)
->
core
.
Gener
icFunction
:
)
->
core
.
Polymorph
icFunction
:
"""Compiles a function into a callable TensorFlow graph.
`tf.function` constructs a `tf.types.experimental.
Gener
icFunction` that
`tf.function` constructs a `tf.types.experimental.
Polymorph
icFunction` that
executes a TensorFlow graph (`tf.Graph`) created by trace-compiling the
TensorFlow operations in `func`. More information on the topic can be found
in [Introduction to Graphs and tf.function]
...
...
@@ -1320,7 +1320,7 @@ def function(
The trace-compilation allows non-TensorFlow operations to execute, but under
special conditions. In general, only TensorFlow operations are guaranteed to
run and create fresh results whenever the `
Gener
icFunction` is called.
run and create fresh results whenever the `
Polymorph
icFunction` is called.
## Features
...
...
@@ -1385,7 +1385,7 @@ def function(
## `tf.function` creates polymorphic callables
Internally, `tf.types.experimental.
Gener
icFunction` may contain multiple
Internally, `tf.types.experimental.
Polymorph
icFunction` may contain multiple
`tf.types.experimental.ConcreteFunction`s, each specialized to arguments with
different data types or shapes, since TensorFlow can perform more
optimizations on graphs of specific shapes, dtypes and values of constant
...
...
@@ -1395,11 +1395,11 @@ def function(
For more information, see the
[tf.function guide](https://www.tensorflow.org/guide/function#rules_of_tracing)
Executing a `
Gener
icFunction` will select and execute the appropriate
Executing a `
Polymorph
icFunction` will select and execute the appropriate
`ConcreteFunction` based on the argument types and values.
To obtain an individual `ConcreteFunction`, use the
`
Gener
icFunction.get_concrete_function` method. It can be called with the
`
Polymorph
icFunction.get_concrete_function` method. It can be called with the
same arguments as `func` and returns a
`tf.types.experimental.ConcreteFunction`. `ConcreteFunction`s are backed by a
single `tf.Graph`:
...
...
@@ -1410,14 +1410,14 @@ def function(
>>> isinstance(f.get_concrete_function(1).graph, tf.Graph)
True
`ConcreteFunction`s can be executed just like `
Gener
icFunction`s, but their
`ConcreteFunction`s can be executed just like `
Polymorph
icFunction`s, but their
input is resticted to the types to which they're specialized.
## Retracing
`ConcreteFunctions` are built (traced) on the fly, as the `
Gener
icFunction` is
`ConcreteFunctions` are built (traced) on the fly, as the `
Polymorph
icFunction` is
called with new TensorFlow types or shapes, or with new Python values as
arguments. When `
Gener
icFunction` builds a new trace, it is said that `func`
arguments. When `
Polymorph
icFunction` builds a new trace, it is said that `func`
is retraced. Retracing is a frequent performance concern for `tf.function` as
it can be considerably slower than executing a graph that's already been
traced. It is ideal to minimize the amount of retracing in your code.
...
...
@@ -1443,7 +1443,7 @@ def function(
## Input signatures
For Tensor arguments, `
Gener
icFunction`creates a new `ConcreteFunction` for
For Tensor arguments, `
Polymorph
icFunction`creates a new `ConcreteFunction` for
every unique set of input shapes and datatypes. The example below creates two
separate `ConcreteFunction`s, each specialized to a different shape:
...
...
@@ -1459,7 +1459,7 @@ def function(
this process. The input signature specifies the shape and type of each
Tensor argument to the function using a `tf.TensorSpec` object. More general
shapes can be used. This ensures only one `ConcreteFunction` is created, and
restricts the `
Gener
icFunction` to the specified shapes and types. It is
restricts the `
Polymorph
icFunction` to the specified shapes and types. It is
an effective way to limit retracing when Tensors have dynamic shapes.
>>> @tf.function(
...
...
@@ -1602,9 +1602,9 @@ def function(
reduce_retracing instead.
Returns:
If `func` is not None, returns a `tf.types.experimental.
Gener
icFunction`.
If `func` is not None, returns a `tf.types.experimental.
Polymorph
icFunction`.
If `func` is None, returns a decorator that, when invoked with a single
`func` argument, returns a `tf.types.experimental.
Gener
icFunction`.
`func` argument, returns a `tf.types.experimental.
Polymorph
icFunction`.
Raises:
`ValueError` when attempting to use `jit_compile=True`, but XLA support is
...
...
tensorflow/python/ops/cond.py
浏览文件 @
778dd23c
...
...
@@ -358,8 +358,8 @@ def _eager_cond_implementation(pred, true_fn, false_fn, strict, name):
# Eager tensors from a parallel device may not have a constant
# value. Running the cond op itself would work, but we don't have logic to
# build cond ops without wrapping in a function first.
if
(
not
isinstance
(
true_fn
,
core
.
Gener
icFunction
)
or
not
isinstance
(
false_fn
,
core
.
Gener
icFunction
)):
if
(
not
isinstance
(
true_fn
,
core
.
Polymorph
icFunction
)
or
not
isinstance
(
false_fn
,
core
.
Polymorph
icFunction
)):
raise
TypeError
(
"When running tf.cond on a parallel device, 'true_fn' "
"and 'false_fn' must be decorated with `tf.function`."
)
functions_run_eagerly
=
eager_function_run
.
functions_run_eagerly
()
...
...
tensorflow/python/saved_model/signature_serialization.py
浏览文件 @
778dd23c
...
...
@@ -226,7 +226,7 @@ def canonicalize_signatures(signatures):
# pylint: enable=protected-access
concrete_signatures
[
signature_key
]
=
final_concrete
# pylint: enable=cell-var-from-loop
if
isinstance
(
function
,
core
.
Gener
icFunction
):
if
isinstance
(
function
,
core
.
Polymorph
icFunction
):
flattened_defaults
=
nest
.
flatten
(
function
.
function_spec
.
fullargspec
.
defaults
# pylint: disable=protected-access
)
...
...
tensorflow/python/trackable/autotrackable.py
浏览文件 @
778dd23c
...
...
@@ -118,7 +118,7 @@ class AutoTrackable(base.Trackable):
# (e.g. captured variables). Make sure we return those too.
children
=
{}
for
name
,
child
in
self
.
_checkpoint_dependencies
:
if
isinstance
(
child
,
(
core_types
.
Gener
icFunction
,
if
isinstance
(
child
,
(
core_types
.
Polymorph
icFunction
,
core_types
.
ConcreteFunction
)):
# Skip "tracked" functions for now since there may be objects that
# automatically track functions that should not be saved.
...
...
tensorflow/python/types/core.py
浏览文件 @
778dd23c
...
...
@@ -183,9 +183,8 @@ class ConcreteFunction(Callable, metaclass=abc.ABCMeta):
"""Returns the original `AtomicFunction` owned by this ConcreteFunction."""
# TODO(mdan): Name just `types.Function`, for historic continuity?
@
tf_export
(
"types.experimental.GenericFunction"
,
v1
=
[])
class
GenericFunction
(
Callable
,
metaclass
=
abc
.
ABCMeta
):
@
tf_export
(
"types.experimental.PolymorphicFunction"
,
v1
=
[])
class
PolymorphicFunction
(
Callable
,
metaclass
=
abc
.
ABCMeta
):
"""Base class for polymorphic graph functions.
Graph functions are Python callable objects that dispatch calls to a
...
...
@@ -365,6 +364,13 @@ class GenericFunction(Callable, metaclass=abc.ABCMeta):
pass
# TODO(b/297237997): Delete this once all usages are removed.
@
tf_export
(
"types.experimental.GenericFunction"
,
v1
=
[])
class
GenericFunction
(
PolymorphicFunction
):
"""Please use tf.types.experimental.PolymorphicFunction instead."""
pass
@
runtime_checkable
class
TensorProtocol
(
Protocol
):
"""Protocol type for objects that can be converted to Tensor."""
...
...
tensorflow/python/types/trace.py
浏览文件 @
778dd23c
...
...
@@ -14,9 +14,9 @@
# ==============================================================================
"""tf.function tracing types.
See `core.
Gener
icFunction` and `core.ConcreteFunction`.
See `core.
Polymorph
icFunction` and `core.ConcreteFunction`.
`
Gener
icFunction` assigns types to call arguments, forming a signature.
`
Polymorph
icFunction` assigns types to call arguments, forming a signature.
Function signatures are used to match arguments to `ConcreteFunction`s.
For example, when a new `ConcreteFunction` is traced, it is assigned a
the signature of the arguments it was traced with. Subsequent call arguments
...
...
tensorflow/tools/api/golden/v2/tensorflow.__internal__.function.-function.pbtxt
浏览文件 @
778dd23c
...
...
@@ -2,6 +2,7 @@ path: "tensorflow.__internal__.function.Function"
tf_class {
is_instance: "<class \'tensorflow.python.eager.polymorphic_function.polymorphic_function.Function\'>"
is_instance: "<class \'tensorflow.python.types.core.GenericFunction\'>"
is_instance: "<class \'tensorflow.python.types.core.PolymorphicFunction\'>"
is_instance: "<class \'tensorflow.python.types.core.Callable\'>"
is_instance: "<class \'tensorflow.python.trackable.base.Trackable\'>"
is_instance: "<type \'object\'>"
...
...
tensorflow/tools/api/golden/v2/tensorflow.types.experimental.-generic-function.pbtxt
浏览文件 @
778dd23c
path: "tensorflow.types.experimental.GenericFunction"
tf_class {
is_instance: "<class \'tensorflow.python.types.core.GenericFunction\'>"
is_instance: "<class \'tensorflow.python.types.core.PolymorphicFunction\'>"
is_instance: "<class \'tensorflow.python.types.core.Callable\'>"
is_instance: "<type \'object\'>"
member {
...
...
tensorflow/tools/api/golden/v2/tensorflow.types.experimental.-polymorphic-function.pbtxt
0 → 100644
浏览文件 @
778dd23c
path: "tensorflow.types.experimental.PolymorphicFunction"
tf_class {
is_instance: "<class \'tensorflow.python.types.core.PolymorphicFunction\'>"
is_instance: "<class \'tensorflow.python.types.core.Callable\'>"
is_instance: "<type \'object\'>"
member {
name: "function_type"
mtype: "<type \'property\'>"
}
member_method {
name: "__init__"
}
member_method {
name: "experimental_get_compiler_ir"
argspec: "args=[\'self\'], varargs=args, keywords=kwargs, defaults=None"
}
member_method {
name: "get_concrete_function"
argspec: "args=[\'self\'], varargs=args, keywords=kwargs, defaults=None"
}
}
tensorflow/tools/api/golden/v2/tensorflow.types.experimental.pbtxt
浏览文件 @
778dd23c
...
...
@@ -20,6 +20,10 @@ tf_module {
name: "GenericFunction"
mtype: "<type \'type\'>"
}
member {
name: "PolymorphicFunction"
mtype: "<type \'type\'>"
}
member {
name: "SupportsTracingProtocol"
mtype: "<class \'typing._ProtocolMeta\'>"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录