Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
曾经的那一瞬间
Models
提交
8bd9aa11
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,发现更多精彩内容 >>
提交
8bd9aa11
编写于
12月 16, 2019
作者:
H
Hongkun Yu
提交者:
A. Unique TensorFlower
12月 16, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make NCF not depend on tf.contrib.
Remove not maintained code path. PiperOrigin-RevId: 285869559
上级
8d9a16ce
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
12 addition
and
37 deletion
+12
-37
official/recommendation/data_pipeline.py
official/recommendation/data_pipeline.py
+1
-4
official/recommendation/ncf_common.py
official/recommendation/ncf_common.py
+0
-11
official/recommendation/ncf_estimator_main.py
official/recommendation/ncf_estimator_main.py
+2
-8
official/recommendation/neumf_model.py
official/recommendation/neumf_model.py
+9
-14
未找到文件。
official/recommendation/data_pipeline.py
浏览文件 @
8bd9aa11
...
...
@@ -39,6 +39,7 @@ from official.recommendation import constants as rconst
from
official.recommendation
import
movielens
from
official.recommendation
import
popen_helper
from
official.recommendation
import
stat_utils
from
tensorflow.python.tpu.datasets
import
StreamingFilesDataset
SUMMARY_TEMPLATE
=
"""General:
...
...
@@ -286,10 +287,6 @@ class DatasetManager(object):
file_pattern
=
os
.
path
.
join
(
epoch_data_dir
,
rconst
.
SHARD_TEMPLATE
.
format
(
"*"
))
# TODO(seemuch): remove this contrib import
# pylint: disable=line-too-long
from
tensorflow.contrib.tpu.python.tpu.datasets
import
StreamingFilesDataset
# pylint: enable=line-too-long
dataset
=
StreamingFilesDataset
(
files
=
file_pattern
,
worker_job
=
popen_helper
.
worker_job
(),
num_parallel_reads
=
rconst
.
NUM_FILE_SHARDS
,
num_epochs
=
1
,
...
...
official/recommendation/ncf_common.py
浏览文件 @
8bd9aa11
...
...
@@ -94,7 +94,6 @@ def parse_flags(flags_obj):
"beta2"
:
flags_obj
.
beta2
,
"epsilon"
:
flags_obj
.
epsilon
,
"match_mlperf"
:
flags_obj
.
ml_perf
,
"use_xla_for_gpu"
:
flags_obj
.
use_xla_for_gpu
,
"epochs_between_evals"
:
FLAGS
.
epochs_between_evals
,
"keras_use_ctl"
:
flags_obj
.
keras_use_ctl
,
"hr_threshold"
:
flags_obj
.
hr_threshold
,
...
...
@@ -307,16 +306,6 @@ def define_ncf_flags():
return
(
eval_batch_size
is
None
or
int
(
eval_batch_size
)
>
rconst
.
NUM_EVAL_NEGATIVES
)
flags
.
DEFINE_bool
(
name
=
"use_xla_for_gpu"
,
default
=
False
,
help
=
flags_core
.
help_wrap
(
"If True, use XLA for the model function. Only works when using a "
"GPU. On TPUs, XLA is always used"
))
xla_message
=
"--use_xla_for_gpu is incompatible with --tpu"
@
flags
.
multi_flags_validator
([
"use_xla_for_gpu"
,
"tpu"
],
message
=
xla_message
)
def
xla_validator
(
flag_dict
):
return
not
flag_dict
[
"use_xla_for_gpu"
]
or
not
flag_dict
[
"tpu"
]
flags
.
DEFINE_bool
(
name
=
"early_stopping"
,
default
=
False
,
...
...
official/recommendation/ncf_estimator_main.py
浏览文件 @
8bd9aa11
...
...
@@ -57,25 +57,19 @@ FLAGS = flags.FLAGS
def
construct_estimator
(
model_dir
,
params
):
"""Construct either an Estimator
or TPUEstimator
for NCF.
"""Construct either an Estimator for NCF.
Args:
model_dir: The model directory for the estimator
params: The params dict for the estimator
Returns:
An Estimator
or TPUEstimator
.
An Estimator.
"""
distribution
=
ncf_common
.
get_v1_distribution_strategy
(
params
)
run_config
=
tf
.
estimator
.
RunConfig
(
train_distribute
=
distribution
,
eval_distribute
=
distribution
)
model_fn
=
neumf_model
.
neumf_model_fn
if
params
[
"use_xla_for_gpu"
]:
# TODO(seemuch): remove the contrib imput
from
tensorflow.contrib.compiler
import
xla
logging
.
info
(
"Using XLA for GPU for training and evaluation."
)
model_fn
=
xla
.
estimator_model_fn
(
model_fn
)
estimator
=
tf
.
estimator
.
Estimator
(
model_fn
=
model_fn
,
model_dir
=
model_dir
,
config
=
run_config
,
params
=
params
)
return
estimator
...
...
official/recommendation/neumf_model.py
浏览文件 @
8bd9aa11
...
...
@@ -93,7 +93,7 @@ def neumf_model_fn(features, labels, mode, params):
duplicate_mask
,
params
[
"num_neg"
],
params
[
"match_mlperf"
],
use_tpu_spec
=
params
[
"use_
xla_for_g
pu"
])
use_tpu_spec
=
params
[
"use_
t
pu"
])
elif
mode
==
tf
.
estimator
.
ModeKeys
.
TRAIN
:
labels
=
tf
.
cast
(
labels
,
tf
.
int32
)
...
...
@@ -269,8 +269,7 @@ def _get_estimator_spec_with_metrics(logits, # type: tf.Tensor
softmax_logits
,
duplicate_mask
,
num_training_neg
,
match_mlperf
,
use_tpu_spec
)
match_mlperf
)
if
use_tpu_spec
:
return
tf
.
estimator
.
tpu
.
TPUEstimatorSpec
(
...
...
@@ -285,13 +284,13 @@ def _get_estimator_spec_with_metrics(logits, # type: tf.Tensor
)
def
compute_eval_loss_and_metrics_helper
(
logits
,
# type: tf.Tensor
softmax_logits
,
# type: tf.Tensor
duplicate_mask
,
# type: tf.Tensor
num_training_neg
,
# type: int
match_mlperf
=
False
,
# type: bool
use_tpu_spec
=
False
# type: bool
):
def
compute_eval_loss_and_metrics_helper
(
logits
,
# type: tf.Tensor
softmax_logits
,
# type: tf.Tensor
duplicate_mask
,
# type: tf.Tensor
num_training_neg
,
# type: int
match_mlperf
=
False
# type: bool
):
"""Model evaluation with HR and NDCG metrics.
The evaluation protocol is to rank the test interacted item (truth items)
...
...
@@ -348,10 +347,6 @@ def compute_eval_loss_and_metrics_helper(logits, # type: tf.Tensor
match_mlperf: Use the MLPerf reference convention for computing rank.
use_tpu_spec: Should a TPUEstimatorSpec be returned instead of an
EstimatorSpec. Required for TPUs and if XLA is done on a GPU. Despite its
name, TPUEstimatorSpecs work with GPUs
Returns:
cross_entropy: the loss
metric_fn: the metrics function
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录