Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
曾经的那一瞬间
Models
提交
467db6c5
M
Models
项目概览
曾经的那一瞬间
/
Models
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
467db6c5
编写于
1月 07, 2023
作者:
H
Hongkun Yu
提交者:
A. Unique TensorFlower
1月 07, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Internal change
PiperOrigin-RevId: 500425343
上级
c5335062
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
23 addition
and
7 deletion
+23
-7
official/core/input_reader.py
official/core/input_reader.py
+2
-2
official/nlp/modeling/layers/on_device_embedding.py
official/nlp/modeling/layers/on_device_embedding.py
+21
-5
official/projects/video_ssl/__init__.py
official/projects/video_ssl/__init__.py
+0
-0
official/projects/video_ssl/dataloaders/__init__.py
official/projects/video_ssl/dataloaders/__init__.py
+0
-0
official/projects/video_ssl/losses/__init__.py
official/projects/video_ssl/losses/__init__.py
+0
-0
official/projects/video_ssl/modeling/__init__.py
official/projects/video_ssl/modeling/__init__.py
+0
-0
official/projects/video_ssl/ops/__init__.py
official/projects/video_ssl/ops/__init__.py
+0
-0
未找到文件。
official/core/input_reader.py
浏览文件 @
467db6c5
...
...
@@ -346,7 +346,7 @@ class InputReader:
@
property
def
tfds_info
(
self
)
->
Union
[
tfds
.
core
.
DatasetInfo
,
D
ict
[
str
,
tfds
.
core
.
DatasetInfo
]]:
d
ict
[
str
,
tfds
.
core
.
DatasetInfo
]]:
"""Returns TFDS dataset info, if available."""
if
self
.
_tfds_builder
:
if
isinstance
(
self
.
_tfds_builder
,
dict
):
...
...
@@ -381,7 +381,7 @@ class InputReader:
input_context
:
Optional
[
tf
.
distribute
.
InputContext
]
=
None
,
tfds_builder
:
Optional
[
Union
[
tfds
.
core
.
DatasetBuilder
,
D
ict
[
str
,
tfds
.
core
.
DatasetBuilder
]]]
=
None
):
d
ict
[
str
,
tfds
.
core
.
DatasetBuilder
]]]
=
None
):
"""Reads the data source (files/tfds) to a dataset."""
def
_files_to_dataset
(
files
:
List
[
str
])
->
tf
.
data
.
Dataset
:
...
...
official/nlp/modeling/layers/on_device_embedding.py
浏览文件 @
467db6c5
...
...
@@ -37,6 +37,9 @@ class OnDeviceEmbedding(tf.keras.layers.Layer):
scale_factor: Whether to scale the output embeddings. Defaults to None (that
is, not to scale). Setting this option to a float will let values in
output embeddings multiplied by scale_factor.
weight_fallback_dtype: When keras mix precision inferred wrong dtype for
varibales, `weight_fallback_dtype` will be used to define the dtype of
weights.
"""
def
__init__
(
self
,
...
...
@@ -45,6 +48,7 @@ class OnDeviceEmbedding(tf.keras.layers.Layer):
initializer
=
"glorot_uniform"
,
use_one_hot
=
False
,
scale_factor
=
None
,
weight_fallback_dtype
=
tf
.
float32
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
...
...
@@ -53,6 +57,10 @@ class OnDeviceEmbedding(tf.keras.layers.Layer):
self
.
_initializer
=
initializer
self
.
_use_one_hot
=
use_one_hot
self
.
_scale_factor
=
scale_factor
# Backup control of the weight dtype because Keras mix precision sometimes
# depends on the input to infer the compute dtype, but the inputs of
# this layer are int type.
self
.
_weight_fallback_dtype
=
weight_fallback_dtype
def
get_config
(
self
):
config
=
{
...
...
@@ -61,28 +69,37 @@ class OnDeviceEmbedding(tf.keras.layers.Layer):
"initializer"
:
self
.
_initializer
,
"use_one_hot"
:
self
.
_use_one_hot
,
"scale_factor"
:
self
.
_scale_factor
,
"weight_fallback_dtype"
:
self
.
_weight_fallback_dtype
,
}
base_config
=
super
().
get_config
()
return
dict
(
list
(
base_config
.
items
())
+
list
(
config
.
items
()))
def
build
(
self
,
input_shape
):
if
(
self
.
dtype
is
not
None
and
not
tf
.
dtypes
.
as_dtype
(
self
.
dtype
).
is_floating
):
# Keras failed to infer the right dtype.
dtype
=
self
.
_weight_fallback_dtype
else
:
dtype
=
self
.
dtype
self
.
embeddings
=
self
.
add_weight
(
"embeddings"
,
shape
=
[
self
.
_vocab_size
,
self
.
_embedding_width
],
initializer
=
self
.
_initializer
,
dtype
=
tf
.
float32
)
dtype
=
dtype
)
super
().
build
(
input_shape
)
def
call
(
self
,
inputs
):
flat_inputs
=
tf
.
reshape
(
inputs
,
[
-
1
])
if
self
.
_use_one_hot
:
dtype
=
self
.
_
compute_dtype
dtype
=
self
.
compute_dtype
if
not
tf
.
dtypes
.
as_dtype
(
dtype
).
is_floating
:
# TensorFlow 1 compatibility. In TF1, self.
_
compute_dtype is int32
# TensorFlow 1 compatibility. In TF1, self.compute_dtype is int32
# instead of a floating-point dtype, as the dtype is inferred from the
# dtype of the inputs
dtype
=
tf
.
float32
dtype
=
self
.
_weight_fallback_dtype
one_hot_data
=
tf
.
one_hot
(
flat_inputs
,
depth
=
self
.
_vocab_size
,
dtype
=
dtype
)
embeddings
=
tf
.
matmul
(
one_hot_data
,
self
.
embeddings
)
...
...
@@ -90,7 +107,6 @@ class OnDeviceEmbedding(tf.keras.layers.Layer):
embeddings
=
tf
.
gather
(
self
.
embeddings
,
flat_inputs
)
embeddings
=
tf
.
reshape
(
embeddings
,
# Work around b/142213824: prefer concat to shape over a Python list.
tf
.
concat
([
tf
.
shape
(
inputs
),
[
self
.
_embedding_width
]],
axis
=
0
))
embeddings
.
set_shape
(
inputs
.
shape
.
as_list
()
+
[
self
.
_embedding_width
])
if
self
.
_scale_factor
:
...
...
official/projects/video_ssl/__init__.py
已删除
100644 → 0
浏览文件 @
c5335062
official/projects/video_ssl/dataloaders/__init__.py
已删除
100644 → 0
浏览文件 @
c5335062
official/projects/video_ssl/losses/__init__.py
已删除
100644 → 0
浏览文件 @
c5335062
official/projects/video_ssl/modeling/__init__.py
已删除
100644 → 0
浏览文件 @
c5335062
official/projects/video_ssl/ops/__init__.py
已删除
100644 → 0
浏览文件 @
c5335062
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录