Skip to content

Commit fed35fd

Browse files
authored
[Docs] Update Sample-awared Graph Compression Document (#747)
- Add Performance result - Remove useless logging
1 parent aea9b3a commit fed35fd

5 files changed

Lines changed: 48 additions & 23 deletions

File tree

docs/docs_en/Sample-awared-Graph-Compression.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,31 @@ TODO
3838
### Inference
3939

4040
```
41+
USER_FEATURE = ['user_feature_0', 'user_feature_1']
42+
ITEM_FEATURE = ['item_feature_0', 'item_feature_1']
43+
ALL_FEATURE = USER_FEATURE + ITEM_FEATURE
44+
4145
def serving_input_receiver_fn():
42-
item_size = tf.placeholder(dtype=tf.int32, shape=[None], name='item_size')
43-
user_tensors=[]
44-
item_tensors=[]
45-
for feature, tensor in feature_map:
46-
if is_user_feature(feature):
47-
user_tensors.append(tensor)
48-
else:
49-
item_tensors.append(tensor)
46+
item_size = tf.placeholder(dtype=tf.int32, shape=[None], name='item_size')
47+
features = {}
48+
inputs = {"item_size": item_size}
49+
user_tensors = []
50+
item_tensors = []
51+
for fea_name in ALL_FEATURE:
52+
features[fea_name] = tf.placeholder(tf.string, [None], name=fea_name)
53+
inputs[fea_name] = features[fea_name]
54+
if fea_name in ITEM_FEATURE:
55+
item_tensors.append(features[fea_name])
56+
else:
57+
user_tensors.append(features[fea_name])
5058
5159
"""Enable Sample-awared Graph Compression"""
5260
tf.graph_optimizer.enable_sample_awared_graph_compression(
5361
user_tensors,
5462
item_tensors,
5563
item_size)
5664
57-
return tf.estimator.export.ServingInputReceiver(feature_map, inputs)
65+
return tf.estimator.export.ServingInputReceiver(features, inputs)
5866
5967
estiamtor = ...
6068
estiamtor.export_savedmodel(output_dir, serving_input_receiver_fn)
@@ -63,3 +71,9 @@ estiamtor.export_savedmodel(output_dir, serving_input_receiver_fn)
6371

6472
2. Input data format
6573
Generally, in the inference scenario, the input data is protobuf, which contains the values of each feature required by the model and the tensor indicating the number of items in the sample. The user tensor shape is [Duser], and the item tensor shape is [N, Ditem]
74+
75+
## Performance
76+
77+
Compressing user-side features reduces the end-to-end delay of Inference. In a cloud online service case, the performance results are as follows:
78+
79+
![img_1.png](Sample-awared-Graph-Compression/img_1.png)
223 KB
Loading

docs/docs_zh/Sample-awared-Graph-Compression.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ user_1_feature, item_2_feature, label_2
1111
user_1_feature, item_N_feature, label_N
1212
```
1313

14-
这导致在样本的存储存在冗余,浪费了存储空间,表达了无效信息量。
14+
这导致在样本的存储存在冗余,浪费了存储/传输空间,表达了无效信息量。
1515
### 模型特点
1616
在这样的样本特点下,读入的冗余样本必然也衍生了计算冗余,针对上面的样本,训练模型的时候,batch内部,user_1_feature会重复的run sub-graph(如:Attention Graph)若干次。这部分计算是完全冗余的,可以在运行时节省掉,只计算一次。
1717
## 功能
@@ -34,23 +34,31 @@ TODO
3434
### Inference
3535

3636
```
37+
USER_FEATURE = ['user_feature_0', 'user_feature_1']
38+
ITEM_FEATURE = ['item_feature_0', 'item_feature_1']
39+
ALL_FEATURE = USER_FEATURE + ITEM_FEATURE
40+
3741
def serving_input_receiver_fn():
38-
item_size = tf.placeholder(dtype=tf.int32, shape=[None], name='item_size')
39-
user_tensors=[]
40-
item_tensors=[]
41-
for feature, tensor in feature_map:
42-
if is_user_feature(feature):
43-
user_tensors.append(tensor)
44-
else:
45-
item_tensors.append(tensor)
42+
item_size = tf.placeholder(dtype=tf.int32, shape=[None], name='item_size')
43+
features = {}
44+
inputs = {"item_size": item_size}
45+
user_tensors = []
46+
item_tensors = []
47+
for fea_name in ALL_FEATURE:
48+
features[fea_name] = tf.placeholder(tf.string, [None], name=fea_name)
49+
inputs[fea_name] = features[fea_name]
50+
if fea_name in ITEM_FEATURE:
51+
item_tensors.append(features[fea_name])
52+
else:
53+
user_tensors.append(features[fea_name])
4654
4755
"""Enable Sample-awared Graph Compression"""
4856
tf.graph_optimizer.enable_sample_awared_graph_compression(
4957
user_tensors,
5058
item_tensors,
5159
item_size)
5260
53-
return tf.estimator.export.ServingInputReceiver(feature_map, inputs)
61+
return tf.estimator.export.ServingInputReceiver(features, inputs)
5462
5563
estiamtor = ...
5664
estiamtor.export_savedmodel(output_dir, serving_input_receiver_fn)
@@ -59,3 +67,8 @@ estiamtor.export_savedmodel(output_dir, serving_input_receiver_fn)
5967

6068
2. 输入数据格式
6169
一般在inference场景下,输入数据为protobuf,protobuf中包含模型所需各个特征的值以及指示该样本中item数目的tensor, user tensor shape为[Duser], item tensor shape为[N, Ditem]
70+
71+
## 性能
72+
该功能,将user侧特征进行压缩,减少了Inference端到端时延,在某云上业务线上服务中,性能结果如下:
73+
74+
![img_1.png](Sample-awared-Graph-Compression/img_1.png)
223 KB
Loading

tensorflow/python/graph_optimizer/sample_awared_graph_compression.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def find_boundery_tensors(user_ops, item_ops):
7676
else:
7777
user_sets.add(op2)
7878
queue_user.append(op2)
79-
logging.info("boundery_tensor_sets: %s", boundery_tensor_sets)
79+
logging.info("[SampleAwaredGraphCompression] boundery_tensor_sets: %s", boundery_tensor_sets)
8080
return user_sets, item_sets, boundery_tensor_sets
8181

8282
def is_shape_op(op):
@@ -94,7 +94,6 @@ def add_tile_op(boundery_tensor_sets, item_seq_length, user_sets, seq_mask_resha
9494
# as some constant operations, such as reshape, should not be tiled
9595
if len(t.get_shape().as_list()) > 0 and not t.get_shape().as_list()[0]:
9696
with ops.colocate_with(t.op):
97-
logging.info("add_tile_op [%d]: %s, %s", tiled_num, t, t.consumers())
9897
user_expand = array_ops.expand_dims(t, 1)
9998
tile_shape = array_ops.concat([[1], item_seq_length, [1 for i in range(len(t.get_shape()[1:]))]], axis=0)
10099
user_tiled = array_ops.tile(user_expand, tile_shape)
@@ -113,9 +112,8 @@ def add_tile_op(boundery_tensor_sets, item_seq_length, user_sets, seq_mask_resha
113112
for index, input_t in enumerate(op.inputs):
114113
if input_t is t:
115114
op._update_input(index, seq_user_input)
116-
logging.info("add_tile_op detail: %s, %s, %s", op, index, seq_user_input)
117115
tiled_num += 1
118-
logging.info("add_tile_op: total %d", tiled_num)
116+
logging.info("[SampleAwaredGraphCompression] add %d TileOp", tiled_num)
119117

120118
class SampleAwaredGraph(object):
121119
# user_tensors: list of common tensor

0 commit comments

Comments
 (0)