easy-cs-rec-custommodel 0.8.6__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of easy-cs-rec-custommodel might be problematic. Click here for more details.

Files changed (336) hide show
  1. easy_cs_rec_custommodel-0.8.6.dist-info/LICENSE +203 -0
  2. easy_cs_rec_custommodel-0.8.6.dist-info/METADATA +48 -0
  3. easy_cs_rec_custommodel-0.8.6.dist-info/RECORD +336 -0
  4. easy_cs_rec_custommodel-0.8.6.dist-info/WHEEL +6 -0
  5. easy_cs_rec_custommodel-0.8.6.dist-info/top_level.txt +2 -0
  6. easy_rec/__init__.py +114 -0
  7. easy_rec/python/__init__.py +0 -0
  8. easy_rec/python/builders/__init__.py +0 -0
  9. easy_rec/python/builders/hyperparams_builder.py +78 -0
  10. easy_rec/python/builders/loss_builder.py +333 -0
  11. easy_rec/python/builders/optimizer_builder.py +211 -0
  12. easy_rec/python/builders/strategy_builder.py +44 -0
  13. easy_rec/python/compat/__init__.py +0 -0
  14. easy_rec/python/compat/adam_s.py +245 -0
  15. easy_rec/python/compat/array_ops.py +229 -0
  16. easy_rec/python/compat/dynamic_variable.py +542 -0
  17. easy_rec/python/compat/early_stopping.py +653 -0
  18. easy_rec/python/compat/embedding_ops.py +162 -0
  19. easy_rec/python/compat/embedding_parallel_saver.py +316 -0
  20. easy_rec/python/compat/estimator_train.py +116 -0
  21. easy_rec/python/compat/exporter.py +473 -0
  22. easy_rec/python/compat/feature_column/__init__.py +0 -0
  23. easy_rec/python/compat/feature_column/feature_column.py +3675 -0
  24. easy_rec/python/compat/feature_column/feature_column_v2.py +5233 -0
  25. easy_rec/python/compat/feature_column/sequence_feature_column.py +648 -0
  26. easy_rec/python/compat/feature_column/utils.py +154 -0
  27. easy_rec/python/compat/layers.py +329 -0
  28. easy_rec/python/compat/ops.py +14 -0
  29. easy_rec/python/compat/optimizers.py +619 -0
  30. easy_rec/python/compat/queues.py +311 -0
  31. easy_rec/python/compat/regularizers.py +208 -0
  32. easy_rec/python/compat/sok_optimizer.py +440 -0
  33. easy_rec/python/compat/sync_replicas_optimizer.py +528 -0
  34. easy_rec/python/compat/weight_decay_optimizers.py +475 -0
  35. easy_rec/python/core/__init__.py +0 -0
  36. easy_rec/python/core/easyrec_metrics/__init__.py +24 -0
  37. easy_rec/python/core/easyrec_metrics/distribute_metrics_impl_pai.py +3702 -0
  38. easy_rec/python/core/easyrec_metrics/distribute_metrics_impl_tf.py +3768 -0
  39. easy_rec/python/core/learning_schedules.py +228 -0
  40. easy_rec/python/core/metrics.py +402 -0
  41. easy_rec/python/core/sampler.py +844 -0
  42. easy_rec/python/eval.py +102 -0
  43. easy_rec/python/export.py +150 -0
  44. easy_rec/python/feature_column/__init__.py +0 -0
  45. easy_rec/python/feature_column/feature_column.py +664 -0
  46. easy_rec/python/feature_column/feature_group.py +89 -0
  47. easy_rec/python/hpo/__init__.py +0 -0
  48. easy_rec/python/hpo/emr_hpo.py +140 -0
  49. easy_rec/python/hpo/generate_hpo_sql.py +71 -0
  50. easy_rec/python/hpo/pai_hpo.py +297 -0
  51. easy_rec/python/inference/__init__.py +0 -0
  52. easy_rec/python/inference/csv_predictor.py +189 -0
  53. easy_rec/python/inference/hive_parquet_predictor.py +200 -0
  54. easy_rec/python/inference/hive_predictor.py +166 -0
  55. easy_rec/python/inference/odps_predictor.py +70 -0
  56. easy_rec/python/inference/parquet_predictor.py +147 -0
  57. easy_rec/python/inference/parquet_predictor_v2.py +147 -0
  58. easy_rec/python/inference/predictor.py +621 -0
  59. easy_rec/python/inference/processor/__init__.py +0 -0
  60. easy_rec/python/inference/processor/test.py +170 -0
  61. easy_rec/python/inference/vector_retrieve.py +124 -0
  62. easy_rec/python/input/__init__.py +0 -0
  63. easy_rec/python/input/batch_tfrecord_input.py +117 -0
  64. easy_rec/python/input/criteo_binary_reader.py +259 -0
  65. easy_rec/python/input/criteo_input.py +107 -0
  66. easy_rec/python/input/csv_input.py +175 -0
  67. easy_rec/python/input/csv_input_ex.py +72 -0
  68. easy_rec/python/input/csv_input_v2.py +68 -0
  69. easy_rec/python/input/datahub_input.py +320 -0
  70. easy_rec/python/input/dummy_input.py +58 -0
  71. easy_rec/python/input/hive_input.py +123 -0
  72. easy_rec/python/input/hive_parquet_input.py +140 -0
  73. easy_rec/python/input/hive_rtp_input.py +174 -0
  74. easy_rec/python/input/input.py +1064 -0
  75. easy_rec/python/input/kafka_dataset.py +144 -0
  76. easy_rec/python/input/kafka_input.py +235 -0
  77. easy_rec/python/input/load_parquet.py +317 -0
  78. easy_rec/python/input/odps_input.py +101 -0
  79. easy_rec/python/input/odps_input_v2.py +110 -0
  80. easy_rec/python/input/odps_input_v3.py +132 -0
  81. easy_rec/python/input/odps_rtp_input.py +187 -0
  82. easy_rec/python/input/odps_rtp_input_v2.py +104 -0
  83. easy_rec/python/input/parquet_input.py +397 -0
  84. easy_rec/python/input/parquet_input_v2.py +180 -0
  85. easy_rec/python/input/parquet_input_v3.py +203 -0
  86. easy_rec/python/input/rtp_input.py +225 -0
  87. easy_rec/python/input/rtp_input_v2.py +145 -0
  88. easy_rec/python/input/tfrecord_input.py +100 -0
  89. easy_rec/python/layers/__init__.py +0 -0
  90. easy_rec/python/layers/backbone.py +571 -0
  91. easy_rec/python/layers/capsule_layer.py +176 -0
  92. easy_rec/python/layers/cmbf.py +390 -0
  93. easy_rec/python/layers/common_layers.py +192 -0
  94. easy_rec/python/layers/dnn.py +87 -0
  95. easy_rec/python/layers/embed_input_layer.py +25 -0
  96. easy_rec/python/layers/fm.py +26 -0
  97. easy_rec/python/layers/input_layer.py +396 -0
  98. easy_rec/python/layers/keras/__init__.py +34 -0
  99. easy_rec/python/layers/keras/activation.py +114 -0
  100. easy_rec/python/layers/keras/attention.py +267 -0
  101. easy_rec/python/layers/keras/auxiliary_loss.py +47 -0
  102. easy_rec/python/layers/keras/blocks.py +262 -0
  103. easy_rec/python/layers/keras/bst.py +119 -0
  104. easy_rec/python/layers/keras/custom_ops.py +250 -0
  105. easy_rec/python/layers/keras/data_augment.py +133 -0
  106. easy_rec/python/layers/keras/din.py +67 -0
  107. easy_rec/python/layers/keras/einsum_dense.py +598 -0
  108. easy_rec/python/layers/keras/embedding.py +81 -0
  109. easy_rec/python/layers/keras/fibinet.py +251 -0
  110. easy_rec/python/layers/keras/interaction.py +416 -0
  111. easy_rec/python/layers/keras/layer_norm.py +364 -0
  112. easy_rec/python/layers/keras/mask_net.py +166 -0
  113. easy_rec/python/layers/keras/multi_head_attention.py +717 -0
  114. easy_rec/python/layers/keras/multi_task.py +125 -0
  115. easy_rec/python/layers/keras/numerical_embedding.py +376 -0
  116. easy_rec/python/layers/keras/ppnet.py +194 -0
  117. easy_rec/python/layers/keras/transformer.py +192 -0
  118. easy_rec/python/layers/layer_norm.py +51 -0
  119. easy_rec/python/layers/mmoe.py +83 -0
  120. easy_rec/python/layers/multihead_attention.py +162 -0
  121. easy_rec/python/layers/multihead_cross_attention.py +749 -0
  122. easy_rec/python/layers/senet.py +73 -0
  123. easy_rec/python/layers/seq_input_layer.py +134 -0
  124. easy_rec/python/layers/sequence_feature_layer.py +249 -0
  125. easy_rec/python/layers/uniter.py +301 -0
  126. easy_rec/python/layers/utils.py +248 -0
  127. easy_rec/python/layers/variational_dropout_layer.py +130 -0
  128. easy_rec/python/loss/__init__.py +0 -0
  129. easy_rec/python/loss/circle_loss.py +82 -0
  130. easy_rec/python/loss/contrastive_loss.py +79 -0
  131. easy_rec/python/loss/f1_reweight_loss.py +38 -0
  132. easy_rec/python/loss/focal_loss.py +93 -0
  133. easy_rec/python/loss/jrc_loss.py +128 -0
  134. easy_rec/python/loss/listwise_loss.py +161 -0
  135. easy_rec/python/loss/multi_similarity.py +68 -0
  136. easy_rec/python/loss/pairwise_loss.py +307 -0
  137. easy_rec/python/loss/softmax_loss_with_negative_mining.py +110 -0
  138. easy_rec/python/loss/zero_inflated_lognormal.py +76 -0
  139. easy_rec/python/main.py +878 -0
  140. easy_rec/python/model/__init__.py +0 -0
  141. easy_rec/python/model/autoint.py +73 -0
  142. easy_rec/python/model/cmbf.py +47 -0
  143. easy_rec/python/model/collaborative_metric_learning.py +182 -0
  144. easy_rec/python/model/custom_model.py +323 -0
  145. easy_rec/python/model/dat.py +138 -0
  146. easy_rec/python/model/dbmtl.py +116 -0
  147. easy_rec/python/model/dcn.py +70 -0
  148. easy_rec/python/model/deepfm.py +106 -0
  149. easy_rec/python/model/dlrm.py +73 -0
  150. easy_rec/python/model/dropoutnet.py +207 -0
  151. easy_rec/python/model/dssm.py +154 -0
  152. easy_rec/python/model/dssm_senet.py +143 -0
  153. easy_rec/python/model/dummy_model.py +48 -0
  154. easy_rec/python/model/easy_rec_estimator.py +739 -0
  155. easy_rec/python/model/easy_rec_model.py +467 -0
  156. easy_rec/python/model/esmm.py +242 -0
  157. easy_rec/python/model/fm.py +63 -0
  158. easy_rec/python/model/match_model.py +357 -0
  159. easy_rec/python/model/mind.py +445 -0
  160. easy_rec/python/model/mmoe.py +70 -0
  161. easy_rec/python/model/multi_task_model.py +303 -0
  162. easy_rec/python/model/multi_tower.py +62 -0
  163. easy_rec/python/model/multi_tower_bst.py +190 -0
  164. easy_rec/python/model/multi_tower_din.py +130 -0
  165. easy_rec/python/model/multi_tower_recall.py +68 -0
  166. easy_rec/python/model/pdn.py +203 -0
  167. easy_rec/python/model/ple.py +120 -0
  168. easy_rec/python/model/rank_model.py +485 -0
  169. easy_rec/python/model/rocket_launching.py +203 -0
  170. easy_rec/python/model/simple_multi_task.py +54 -0
  171. easy_rec/python/model/uniter.py +46 -0
  172. easy_rec/python/model/wide_and_deep.py +121 -0
  173. easy_rec/python/ops/1.12/incr_record.so +0 -0
  174. easy_rec/python/ops/1.12/kafka.so +0 -0
  175. easy_rec/python/ops/1.12/libcustom_ops.so +0 -0
  176. easy_rec/python/ops/1.12/libembed_op.so +0 -0
  177. easy_rec/python/ops/1.12/libhiredis.so.1.0.0 +0 -0
  178. easy_rec/python/ops/1.12/librdkafka++.so.1 +0 -0
  179. easy_rec/python/ops/1.12/librdkafka.so.1 +0 -0
  180. easy_rec/python/ops/1.12/libredis++.so +0 -0
  181. easy_rec/python/ops/1.12/libredis++.so.1 +0 -0
  182. easy_rec/python/ops/1.12/libredis++.so.1.2.3 +0 -0
  183. easy_rec/python/ops/1.12/libstr_avx_op.so +0 -0
  184. easy_rec/python/ops/1.12/libwrite_sparse_kv.so +0 -0
  185. easy_rec/python/ops/1.15/incr_record.so +0 -0
  186. easy_rec/python/ops/1.15/kafka.so +0 -0
  187. easy_rec/python/ops/1.15/libcustom_ops.so +0 -0
  188. easy_rec/python/ops/1.15/libembed_op.so +0 -0
  189. easy_rec/python/ops/1.15/libhiredis.so.1.0.0 +0 -0
  190. easy_rec/python/ops/1.15/librdkafka++.so +0 -0
  191. easy_rec/python/ops/1.15/librdkafka++.so.1 +0 -0
  192. easy_rec/python/ops/1.15/librdkafka.so +0 -0
  193. easy_rec/python/ops/1.15/librdkafka.so.1 +0 -0
  194. easy_rec/python/ops/1.15/libredis++.so.1 +0 -0
  195. easy_rec/python/ops/1.15/libstr_avx_op.so +0 -0
  196. easy_rec/python/ops/2.12/libcustom_ops.so +0 -0
  197. easy_rec/python/ops/2.12/libload_embed.so +0 -0
  198. easy_rec/python/ops/2.12/libstr_avx_op.so +0 -0
  199. easy_rec/python/ops/__init__.py +0 -0
  200. easy_rec/python/ops/gen_kafka_ops.py +193 -0
  201. easy_rec/python/ops/gen_str_avx_op.py +28 -0
  202. easy_rec/python/ops/incr_record.py +30 -0
  203. easy_rec/python/predict.py +170 -0
  204. easy_rec/python/protos/__init__.py +0 -0
  205. easy_rec/python/protos/autoint_pb2.py +122 -0
  206. easy_rec/python/protos/backbone_pb2.py +1416 -0
  207. easy_rec/python/protos/cmbf_pb2.py +435 -0
  208. easy_rec/python/protos/collaborative_metric_learning_pb2.py +252 -0
  209. easy_rec/python/protos/custom_model_pb2.py +57 -0
  210. easy_rec/python/protos/dat_pb2.py +262 -0
  211. easy_rec/python/protos/data_source_pb2.py +422 -0
  212. easy_rec/python/protos/dataset_pb2.py +1920 -0
  213. easy_rec/python/protos/dbmtl_pb2.py +191 -0
  214. easy_rec/python/protos/dcn_pb2.py +197 -0
  215. easy_rec/python/protos/deepfm_pb2.py +163 -0
  216. easy_rec/python/protos/dlrm_pb2.py +163 -0
  217. easy_rec/python/protos/dnn_pb2.py +329 -0
  218. easy_rec/python/protos/dropoutnet_pb2.py +239 -0
  219. easy_rec/python/protos/dssm_pb2.py +262 -0
  220. easy_rec/python/protos/dssm_senet_pb2.py +282 -0
  221. easy_rec/python/protos/easy_rec_model_pb2.py +1672 -0
  222. easy_rec/python/protos/esmm_pb2.py +133 -0
  223. easy_rec/python/protos/eval_pb2.py +930 -0
  224. easy_rec/python/protos/export_pb2.py +379 -0
  225. easy_rec/python/protos/feature_config_pb2.py +1359 -0
  226. easy_rec/python/protos/fm_pb2.py +90 -0
  227. easy_rec/python/protos/hive_config_pb2.py +138 -0
  228. easy_rec/python/protos/hyperparams_pb2.py +624 -0
  229. easy_rec/python/protos/keras_layer_pb2.py +692 -0
  230. easy_rec/python/protos/layer_pb2.py +1936 -0
  231. easy_rec/python/protos/loss_pb2.py +1713 -0
  232. easy_rec/python/protos/mind_pb2.py +497 -0
  233. easy_rec/python/protos/mmoe_pb2.py +215 -0
  234. easy_rec/python/protos/multi_tower_pb2.py +295 -0
  235. easy_rec/python/protos/multi_tower_recall_pb2.py +198 -0
  236. easy_rec/python/protos/optimizer_pb2.py +2017 -0
  237. easy_rec/python/protos/pdn_pb2.py +293 -0
  238. easy_rec/python/protos/pipeline_pb2.py +516 -0
  239. easy_rec/python/protos/ple_pb2.py +231 -0
  240. easy_rec/python/protos/predict_pb2.py +1140 -0
  241. easy_rec/python/protos/rocket_launching_pb2.py +169 -0
  242. easy_rec/python/protos/seq_encoder_pb2.py +1084 -0
  243. easy_rec/python/protos/simi_pb2.py +54 -0
  244. easy_rec/python/protos/simple_multi_task_pb2.py +97 -0
  245. easy_rec/python/protos/tf_predict_pb2.py +630 -0
  246. easy_rec/python/protos/tower_pb2.py +661 -0
  247. easy_rec/python/protos/train_pb2.py +1197 -0
  248. easy_rec/python/protos/uniter_pb2.py +307 -0
  249. easy_rec/python/protos/variational_dropout_pb2.py +91 -0
  250. easy_rec/python/protos/wide_and_deep_pb2.py +131 -0
  251. easy_rec/python/test/__init__.py +0 -0
  252. easy_rec/python/test/csv_input_test.py +340 -0
  253. easy_rec/python/test/custom_early_stop_func.py +19 -0
  254. easy_rec/python/test/dh_local_run.py +104 -0
  255. easy_rec/python/test/embed_test.py +155 -0
  256. easy_rec/python/test/emr_run.py +119 -0
  257. easy_rec/python/test/eval_metric_test.py +107 -0
  258. easy_rec/python/test/excel_convert_test.py +64 -0
  259. easy_rec/python/test/export_test.py +513 -0
  260. easy_rec/python/test/fg_test.py +70 -0
  261. easy_rec/python/test/hive_input_test.py +311 -0
  262. easy_rec/python/test/hpo_test.py +235 -0
  263. easy_rec/python/test/kafka_test.py +373 -0
  264. easy_rec/python/test/local_incr_test.py +122 -0
  265. easy_rec/python/test/loss_test.py +110 -0
  266. easy_rec/python/test/odps_command.py +61 -0
  267. easy_rec/python/test/odps_local_run.py +86 -0
  268. easy_rec/python/test/odps_run.py +254 -0
  269. easy_rec/python/test/odps_test_cls.py +39 -0
  270. easy_rec/python/test/odps_test_prepare.py +198 -0
  271. easy_rec/python/test/odps_test_util.py +237 -0
  272. easy_rec/python/test/pre_check_test.py +54 -0
  273. easy_rec/python/test/predictor_test.py +394 -0
  274. easy_rec/python/test/rtp_convert_test.py +133 -0
  275. easy_rec/python/test/run.py +138 -0
  276. easy_rec/python/test/train_eval_test.py +1299 -0
  277. easy_rec/python/test/util_test.py +85 -0
  278. easy_rec/python/test/zero_inflated_lognormal_test.py +53 -0
  279. easy_rec/python/tools/__init__.py +0 -0
  280. easy_rec/python/tools/add_boundaries_to_config.py +67 -0
  281. easy_rec/python/tools/add_feature_info_to_config.py +145 -0
  282. easy_rec/python/tools/convert_config_format.py +48 -0
  283. easy_rec/python/tools/convert_rtp_data.py +79 -0
  284. easy_rec/python/tools/convert_rtp_fg.py +106 -0
  285. easy_rec/python/tools/create_config_from_excel.py +427 -0
  286. easy_rec/python/tools/criteo/__init__.py +0 -0
  287. easy_rec/python/tools/criteo/convert_data.py +157 -0
  288. easy_rec/python/tools/edit_lookup_graph.py +134 -0
  289. easy_rec/python/tools/faiss_index_pai.py +116 -0
  290. easy_rec/python/tools/feature_selection.py +316 -0
  291. easy_rec/python/tools/hit_rate_ds.py +223 -0
  292. easy_rec/python/tools/hit_rate_pai.py +138 -0
  293. easy_rec/python/tools/pre_check.py +120 -0
  294. easy_rec/python/tools/predict_and_chk.py +111 -0
  295. easy_rec/python/tools/read_kafka.py +55 -0
  296. easy_rec/python/tools/split_model_pai.py +286 -0
  297. easy_rec/python/tools/split_pdn_model_pai.py +272 -0
  298. easy_rec/python/tools/test_saved_model.py +80 -0
  299. easy_rec/python/tools/view_saved_model.py +39 -0
  300. easy_rec/python/tools/write_kafka.py +65 -0
  301. easy_rec/python/train_eval.py +325 -0
  302. easy_rec/python/utils/__init__.py +15 -0
  303. easy_rec/python/utils/activation.py +120 -0
  304. easy_rec/python/utils/check_utils.py +87 -0
  305. easy_rec/python/utils/compat.py +14 -0
  306. easy_rec/python/utils/config_util.py +652 -0
  307. easy_rec/python/utils/constant.py +43 -0
  308. easy_rec/python/utils/convert_rtp_fg.py +616 -0
  309. easy_rec/python/utils/dag.py +192 -0
  310. easy_rec/python/utils/distribution_utils.py +268 -0
  311. easy_rec/python/utils/ds_util.py +65 -0
  312. easy_rec/python/utils/embedding_utils.py +73 -0
  313. easy_rec/python/utils/estimator_utils.py +1036 -0
  314. easy_rec/python/utils/export_big_model.py +630 -0
  315. easy_rec/python/utils/expr_util.py +118 -0
  316. easy_rec/python/utils/fg_util.py +53 -0
  317. easy_rec/python/utils/hit_rate_utils.py +220 -0
  318. easy_rec/python/utils/hive_utils.py +183 -0
  319. easy_rec/python/utils/hpo_util.py +137 -0
  320. easy_rec/python/utils/hvd_utils.py +56 -0
  321. easy_rec/python/utils/input_utils.py +108 -0
  322. easy_rec/python/utils/io_util.py +282 -0
  323. easy_rec/python/utils/load_class.py +249 -0
  324. easy_rec/python/utils/meta_graph_editor.py +941 -0
  325. easy_rec/python/utils/multi_optimizer.py +62 -0
  326. easy_rec/python/utils/numpy_utils.py +18 -0
  327. easy_rec/python/utils/odps_util.py +79 -0
  328. easy_rec/python/utils/pai_util.py +86 -0
  329. easy_rec/python/utils/proto_util.py +90 -0
  330. easy_rec/python/utils/restore_filter.py +89 -0
  331. easy_rec/python/utils/shape_utils.py +432 -0
  332. easy_rec/python/utils/static_shape.py +71 -0
  333. easy_rec/python/utils/test_utils.py +866 -0
  334. easy_rec/python/utils/tf_utils.py +56 -0
  335. easy_rec/version.py +4 -0
  336. test/__init__.py +0 -0
@@ -0,0 +1,311 @@
1
+ # -*- encoding:utf-8 -*-
2
+ # Copyright (c) Alibaba, Inc. and its affiliates.
3
+ """Define cv_input, the base class for cv tasks."""
4
+ import logging
5
+ import os
6
+ import unittest
7
+
8
+ import tensorflow as tf
9
+ from google.protobuf import text_format
10
+
11
+ from easy_rec.python.input.hive_input import HiveInput
12
+ from easy_rec.python.protos.dataset_pb2 import DatasetConfig
13
+ from easy_rec.python.protos.feature_config_pb2 import FeatureConfig
14
+ from easy_rec.python.protos.hive_config_pb2 import HiveConfig
15
+ from easy_rec.python.protos.pipeline_pb2 import EasyRecConfig
16
+ from easy_rec.python.utils import config_util
17
+ from easy_rec.python.utils import test_utils
18
+
19
+ if tf.__version__ >= '2.0':
20
+ import tensorflow.compat.v1 as tf
21
+
22
+ gfile = tf.gfile
23
+
24
+ if tf.__version__ >= '2.0':
25
+ from tensorflow.python.framework.ops import disable_eager_execution
26
+
27
+ disable_eager_execution()
28
+ tf = tf.compat.v1
29
+
30
+
31
+ class HiveInputTest(tf.test.TestCase):
32
+
33
+ def _init_config(self):
34
+ hive_host = os.environ['hive_host']
35
+ hive_username = os.environ['hive_username']
36
+ hive_table_name = os.environ['hive_table_name']
37
+ hive_hash_fields = os.environ['hive_hash_fields']
38
+
39
+ hive_train_input = """
40
+ host: "{}"
41
+ username: "{}"
42
+ table_name: "{}"
43
+ limit_num: 500
44
+ hash_fields: "{}"
45
+ """.format(hive_host, hive_username, hive_table_name, hive_hash_fields)
46
+ hive_eval_input = """
47
+ host: "{}"
48
+ username: "{}"
49
+ table_name: "{}"
50
+ limit_num: 500
51
+ hash_fields: "{}"
52
+ """.format(hive_host, hive_username, hive_table_name, hive_hash_fields)
53
+ self.hive_train_input_config = HiveConfig()
54
+ text_format.Merge(hive_train_input, self.hive_train_input_config)
55
+
56
+ self.hive_eval_input_config = HiveConfig()
57
+ text_format.Merge(hive_eval_input, self.hive_eval_input_config)
58
+
59
+ def __init__(self, methodName='HiveInputTest'):
60
+ super(HiveInputTest, self).__init__(methodName=methodName)
61
+
62
+ @unittest.skipIf('hive_host' not in os.environ or
63
+ 'hive_username' not in os.environ or
64
+ 'hive_table_name' not in os.environ or
65
+ 'hive_hash_fields' not in os.environ,
66
+ """Only execute hive_config var are specified,hive_host、
67
+ hive_username、hive_table_name、hive_hash_fields is available.""")
68
+ def test_hive_input(self):
69
+ self._init_config()
70
+ data_config_str = """
71
+ batch_size: 1024
72
+ label_fields: "label_1"
73
+ label_fields: "label_2"
74
+ num_epochs: 1
75
+ prefetch_size: 32
76
+ input_type: HiveInput
77
+ input_fields {
78
+ input_name:'label_1'
79
+ input_type: INT32
80
+ }
81
+ input_fields {
82
+ input_name:'label_2'
83
+ input_type: INT32
84
+ }
85
+ input_fields {
86
+ input_name:'age'
87
+ input_type: INT32
88
+ }
89
+ input_fields {
90
+ input_name: "class_of_worker"
91
+ }
92
+ input_fields {
93
+ input_name: "industry_code"
94
+ }
95
+ input_fields {
96
+ input_name: "occupation_code"
97
+ }
98
+ input_fields {
99
+ input_name: "education"
100
+ }
101
+ input_fields {
102
+ input_name: "wage_per_hour"
103
+ input_type: DOUBLE
104
+ }
105
+ input_fields {
106
+ input_name: "enrolled_in_edu_inst_last_wk"
107
+ }
108
+ input_fields {
109
+ input_name: "major_industry"
110
+ }
111
+ input_fields {
112
+ input_name: "major_occupation"
113
+ }
114
+ input_fields {
115
+ input_name: "mace"
116
+ }
117
+ input_fields {
118
+ input_name: "hispanic_origin"
119
+ }
120
+ input_fields {
121
+ input_name: "sex"
122
+ }
123
+ input_fields {
124
+ input_name: "member_of_a_labor_union"
125
+ }
126
+ input_fields {
127
+ input_name: "reason_for_unemployment"
128
+ }
129
+ input_fields {
130
+ input_name: "full_or_part_time_employment_stat"
131
+ }
132
+ input_fields {
133
+ input_name: "capital_gains"
134
+ input_type: DOUBLE
135
+ }
136
+ input_fields {
137
+ input_name: "capital_losses"
138
+ input_type: DOUBLE
139
+ }
140
+ input_fields {
141
+ input_name: "divdends_from_stocks"
142
+ input_type: DOUBLE
143
+ }
144
+ input_fields {
145
+ input_name: "tax_filer_status"
146
+ }
147
+ input_fields {
148
+ input_name: "region_of_previous_residence"
149
+ }
150
+ input_fields {
151
+ input_name: "state_of_previous_residence"
152
+ }
153
+ input_fields {
154
+ input_name: "detailed_household_and_family_stat"
155
+ }
156
+ input_fields {
157
+ input_name: "detailed_household_summary_in_household"
158
+ }
159
+ input_fields {
160
+ input_name: "instance_weight"
161
+ }
162
+ input_fields {
163
+ input_name: "migration_code_change_in_msa"
164
+ }
165
+ input_fields {
166
+ input_name: "migration_code_change_in_reg"
167
+ }
168
+ input_fields {
169
+ input_name: "migration_code_move_within_reg"
170
+ }
171
+ input_fields {
172
+ input_name: "live_in_this_house_1_year_ago"
173
+ }
174
+ input_fields {
175
+ input_name: "migration_prev_res_in_sunbelt"
176
+ }
177
+ input_fields {
178
+ input_name: "num_persons_worked_for_employer"
179
+ input_type: INT32
180
+ }
181
+ input_fields {
182
+ input_name: "family_members_under_18"
183
+ }
184
+ input_fields {
185
+ input_name: "country_of_birth_father"
186
+ }
187
+ input_fields {
188
+ input_name: "country_of_birth_mother"
189
+ }
190
+ input_fields {
191
+ input_name: "country_of_birth_self"
192
+ }
193
+ input_fields {
194
+ input_name: "citizenship"
195
+ }
196
+ input_fields {
197
+ input_name: "own_business_or_self_employed"
198
+ }
199
+ input_fields {
200
+ input_name: "fill_inc_questionnaire_for_veteran_s_admin"
201
+ }
202
+ input_fields {
203
+ input_name: "veterans_benefits"
204
+ }
205
+ input_fields {
206
+ input_name: "weeks_worked_in_year"
207
+ input_type: INT32
208
+ }
209
+ input_fields {
210
+ input_name: "year"
211
+ }
212
+ """
213
+
214
+ feature_config_str = """
215
+ input_names: "own_business_or_self_employed"
216
+ feature_type: IdFeature
217
+ embedding_dim: 9
218
+ hash_bucket_size: 400
219
+ embedding_name: "feature"
220
+ """
221
+
222
+ dataset_config = DatasetConfig()
223
+ text_format.Merge(data_config_str, dataset_config)
224
+ feature_config = FeatureConfig()
225
+ text_format.Merge(feature_config_str, feature_config)
226
+ feature_configs = [feature_config]
227
+
228
+ empty_config = FeatureConfig()
229
+ empty_config.CopyFrom(feature_config)
230
+ while len(empty_config.input_names) > 0:
231
+ empty_config.input_names.pop()
232
+ while len(empty_config.shared_names) > 0:
233
+ empty_config.shared_names.pop()
234
+ train_input_fn = HiveInput(dataset_config, feature_configs,
235
+ self.hive_train_input_config).create_input()
236
+ dataset = train_input_fn(mode=tf.estimator.ModeKeys.TRAIN)
237
+ iterator = dataset.make_initializable_iterator()
238
+ tf.add_to_collection(tf.GraphKeys.TABLE_INITIALIZERS, iterator.initializer)
239
+ features, labels = iterator.get_next()
240
+ init_op = tf.get_collection(tf.GraphKeys.TABLE_INITIALIZERS)
241
+ gpu_options = tf.GPUOptions(allow_growth=True)
242
+ session_config = tf.ConfigProto(
243
+ gpu_options=gpu_options,
244
+ allow_soft_placement=True,
245
+ log_device_placement=False)
246
+ with self.test_session(config=session_config) as sess:
247
+ sess.run(init_op)
248
+ feature_dict, label_dict = sess.run([features, labels])
249
+ for key in feature_dict:
250
+ print(key, feature_dict[key][:5])
251
+
252
+ for key in label_dict:
253
+ print(key, label_dict[key][:5])
254
+ return 0
255
+
256
+ @unittest.skipIf('hive_host' not in os.environ or
257
+ 'hive_username' not in os.environ or
258
+ 'hive_table_name' not in os.environ or
259
+ 'hive_hash_fields' not in os.environ,
260
+ """Only execute hive_config var are specified,hive_host、
261
+ hive_username、hive_table_name、hive_hash_fields is available.""")
262
+ def test_mmoe(self):
263
+ pipeline_config_path = 'samples/emr_script/mmoe/mmoe_census_income.config'
264
+ gpus = test_utils.get_available_gpus()
265
+ if len(gpus) > 0:
266
+ test_utils.set_gpu_id(gpus[0])
267
+ else:
268
+ test_utils.set_gpu_id(None)
269
+
270
+ if not isinstance(pipeline_config_path, EasyRecConfig):
271
+ logging.info('testing pipeline config %s' % pipeline_config_path)
272
+ if 'TF_CONFIG' in os.environ:
273
+ del os.environ['TF_CONFIG']
274
+
275
+ if isinstance(pipeline_config_path, EasyRecConfig):
276
+ pipeline_config = pipeline_config_path
277
+ else:
278
+ pipeline_config = test_utils._load_config_for_test(
279
+ pipeline_config_path, self._test_dir)
280
+
281
+ pipeline_config.train_config.train_distribute = 0
282
+ pipeline_config.train_config.num_gpus_per_worker = 1
283
+ pipeline_config.train_config.sync_replicas = False
284
+
285
+ config_util.save_pipeline_config(pipeline_config, self._test_dir)
286
+ test_pipeline_config_path = os.path.join(self._test_dir, 'pipeline.config')
287
+ hyperparam_str = ''
288
+ train_cmd = 'python -m easy_rec.python.train_eval --pipeline_config_path %s %s' % (
289
+ test_pipeline_config_path, hyperparam_str)
290
+ proc = test_utils.run_cmd(train_cmd,
291
+ '%s/log_%s.txt' % (self._test_dir, 'master'))
292
+ proc.wait()
293
+ if proc.returncode != 0:
294
+ logging.error('train %s failed' % test_pipeline_config_path)
295
+ return 1
296
+ return 0
297
+
298
+ def setUp(self):
299
+ logging.info('Testing %s.%s' % (type(self).__name__, self._testMethodName))
300
+ self._test_dir = test_utils.get_tmp_dir()
301
+ self._success = True
302
+ logging.info('test dir: %s' % self._test_dir)
303
+
304
+ def tearDown(self):
305
+ test_utils.set_gpu_id(None)
306
+ if self._success:
307
+ test_utils.clean_up(self._test_dir)
308
+
309
+
310
+ if __name__ == '__main__':
311
+ tf.test.main()
@@ -0,0 +1,235 @@
1
+ # -*- encoding:utf-8 -*-
2
+ # Copyright (c) Alibaba, Inc. and its affiliates.
3
+
4
+ import json
5
+ import logging
6
+ import os
7
+ import time
8
+
9
+ import numpy as np
10
+ import tensorflow as tf
11
+
12
+ from easy_rec.python.protos.feature_config_pb2 import FeatureConfig
13
+ from easy_rec.python.utils import config_util
14
+ from easy_rec.python.utils import hpo_util
15
+ from easy_rec.python.utils import test_utils
16
+
17
+ if tf.__version__ >= '2.0':
18
+ import tensorflow.io.gfile as gfile
19
+ from tensorflow.core.protobuf import config_pb2
20
+
21
+ ConfigProto = config_pb2.ConfigProto
22
+ GPUOptions = config_pb2.GPUOptions
23
+ else:
24
+ from tensorflow.python.platform import gfile
25
+ GPUOptions = tf.GPUOptions
26
+ ConfigProto = tf.ConfigProto
27
+
28
+
29
+ class HPOTest(tf.test.TestCase):
30
+
31
+ def __init__(self, methodName='HPOTest'):
32
+ super(HPOTest, self).__init__(methodName=methodName)
33
+ self._metric_data_path = 'data/test/hpo_test/eval_val/*.tfevents.*'
34
+
35
+ def test_get_metric(self):
36
+ vals = hpo_util.get_all_eval_result(self._metric_data_path)
37
+ logging.info('eval result num = %d' % len(vals))
38
+ logging.info('eval result[0] = %s' % json.dumps(vals[0]))
39
+
40
+ def load_config(self, config_path):
41
+ with gfile.GFile(config_path, 'r') as fin:
42
+ return json.load(fin)['param']
43
+
44
+ def test_save_eval_metrics(self):
45
+ test_dir = test_utils.get_tmp_dir()
46
+ tmp_file = os.path.join(test_dir,
47
+ 'easy_rec_hpo_test_%d.metric' % time.time())
48
+ hpo_util.save_eval_metrics('data/test/hpo_test/', tmp_file, False)
49
+ test_utils.clean_up(test_dir)
50
+
51
+ def test_edit_config(self):
52
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
53
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
54
+ tmp_file = 'samples/hpo/hpo_param.json'
55
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
56
+ assert tmp_config.feature_config.features[0].embedding_dim == 120
57
+
58
+ def test_edit_config_v2(self):
59
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
60
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
61
+ tmp_file = 'samples/hpo/hpo_param_v2.json'
62
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
63
+ for tmp_fea in tmp_config.feature_configs:
64
+ if tmp_fea.input_names[0] == 'site_id':
65
+ assert tmp_fea.embedding_dim == 32
66
+ else:
67
+ assert tmp_fea.embedding_dim == 16
68
+
69
+ def test_edit_config_v3(self):
70
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
71
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
72
+ tmp_file = 'samples/hpo/hpo_param_v3.json'
73
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
74
+ for i, tmp_fea in enumerate(tmp_config.feature_configs):
75
+ if i >= 10 and i < 20:
76
+ assert tmp_fea.embedding_dim == 37
77
+ else:
78
+ assert tmp_fea.embedding_dim == 16
79
+
80
+ def test_edit_config_v4(self):
81
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
82
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
83
+ tmp_file = 'samples/hpo/hpo_param_v4.json'
84
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
85
+ for i, tmp_fea in enumerate(tmp_config.feature_configs):
86
+ if i < 15:
87
+ assert tmp_fea.embedding_dim == 37
88
+ else:
89
+ assert tmp_fea.embedding_dim == 16
90
+
91
+ def test_edit_config_v5(self):
92
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
93
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
94
+ tmp_file = 'samples/hpo/hpo_param_v5.json'
95
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
96
+ for i, tmp_fea in enumerate(tmp_config.feature_configs):
97
+ if i >= 5:
98
+ assert tmp_fea.embedding_dim == 37
99
+ else:
100
+ assert tmp_fea.embedding_dim == 16
101
+
102
+ def test_edit_config_v51(self):
103
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
104
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
105
+ tmp_file = 'samples/hpo/hpo_param_v51.json'
106
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
107
+ for i, tmp_fea in enumerate(tmp_config.feature_configs):
108
+ if i == 5:
109
+ assert tmp_fea.embedding_dim == 37
110
+
111
+ def test_edit_config_v6(self):
112
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
113
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
114
+ tmp_file = 'samples/hpo/hpo_param_v6.json'
115
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
116
+ for i, tmp_fea in enumerate(tmp_config.feature_configs):
117
+ if tmp_fea.input_names[0] >= 'site':
118
+ assert tmp_fea.embedding_dim == 32, 'input_name = %s %d' % (
119
+ tmp_fea.input_names[0], tmp_fea.embedding_dim)
120
+ else:
121
+ assert tmp_fea.embedding_dim == 16
122
+
123
+ def test_edit_config_v7(self):
124
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
125
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
126
+ tmp_file = 'samples/hpo/hpo_param_v7.json'
127
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
128
+ for i, tmp_fea in enumerate(tmp_config.feature_configs):
129
+ if tmp_fea.input_names[0] == 'c21':
130
+ assert len(tmp_fea.boundaries) == 4 and np.abs(tmp_fea.boundaries[0] -
131
+ 10.0) < 1e-5
132
+
133
+ def test_edit_config_v71(self):
134
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
135
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
136
+ tmp_file = 'samples/hpo/hpo_param_v71.json'
137
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
138
+ for i, tmp_fea in enumerate(tmp_config.feature_configs):
139
+ if tmp_fea.input_names[0] == 'c21':
140
+ assert len(tmp_fea.boundaries) == 4 and np.abs(tmp_fea.boundaries[0] -
141
+ 10.0) < 1e-5
142
+
143
+ def test_edit_config_v8(self):
144
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
145
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
146
+ tmp_file = 'samples/hpo/hpo_param_v8.json'
147
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
148
+ for i, tmp_fea in enumerate(tmp_config.feature_configs):
149
+ if tmp_fea.input_names[0] == 'c21':
150
+ assert len(tmp_fea.boundaries) == 4 and np.abs(tmp_fea.boundaries[0] -
151
+ 4.0) < 1e-5
152
+ assert tmp_fea.embedding_dim == 32
153
+
154
+ def test_edit_config_v81(self):
155
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
156
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
157
+ tmp_file = 'samples/hpo/hpo_param_v81.json'
158
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
159
+ for i, tmp_fea in enumerate(tmp_config.feature_configs):
160
+ if tmp_fea.feature_type == tmp_fea.RawFeature:
161
+ assert tmp_fea.embedding_dim == 24
162
+
163
+ def test_edit_config_v9(self):
164
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
165
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
166
+ tmp_file = 'samples/hpo/hpo_param_v9.json'
167
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
168
+ assert tmp_config.train_config.fine_tune_checkpoint == \
169
+ 'oss://easy-rec/test/experiment/ctr_v93/model.ckpt-1000'
170
+
171
+ def test_edit_config_v10(self):
172
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
173
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
174
+ tmp_file = 'samples/hpo/hpo_param_v10.json'
175
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
176
+ for i, tmp_fea in enumerate(tmp_config.feature_configs):
177
+ if tmp_fea.input_names[0] == 'c21':
178
+ assert len(tmp_fea.boundaries) == 4 and np.abs(tmp_fea.boundaries[0] -
179
+ 4.0) < 1e-5
180
+ assert tmp_fea.embedding_dim == 32
181
+
182
+ def test_edit_config_v11(self):
183
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
184
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
185
+ tmp_file = 'samples/hpo/hpo_param_v11.json'
186
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
187
+ for i, tmp_fea in enumerate(tmp_config.feature_configs):
188
+ if tmp_fea.input_names[0] == 'c21':
189
+ assert len(tmp_fea.boundaries) == 4 and np.abs(tmp_fea.boundaries[0] -
190
+ 10.0) < 1e-5
191
+
192
+ def test_edit_config_v12(self):
193
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
194
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
195
+ tmp_file = 'samples/hpo/hpo_param_v12.json'
196
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
197
+ for i, tmp_fea in enumerate(tmp_config.feature_configs):
198
+ if tmp_fea.input_names[0] == 'c21':
199
+ assert len(tmp_fea.boundaries) == 25
200
+ assert np.abs(tmp_fea.boundaries[1] - 21.0) < 1e-5
201
+
202
+ def test_edit_config_v13(self):
203
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
204
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
205
+ tmp_file = 'samples/hpo/hpo_param_v13.json'
206
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
207
+ assert not tmp_config.export_config.multi_placeholder
208
+
209
+ def test_edit_config_v14(self):
210
+ tmp_file = 'samples/model_config/deepfm_multi_cls_on_avazu_ctr.config'
211
+ tmp_config = config_util.get_configs_from_pipeline_file(tmp_file)
212
+ tmp_file = 'samples/hpo/hpo_param_v14.json'
213
+ tmp_config = config_util.edit_config(tmp_config, self.load_config(tmp_file))
214
+ for i, tmp_fea in enumerate(tmp_config.feature_configs):
215
+ if tmp_fea.input_names[0] == 'hour':
216
+ assert len(tmp_fea.feature_type) == FeatureConfig.RawFeature
217
+
218
+ def test_save_eval_metrics_with_env(self):
219
+ os.environ['TF_CONFIG'] = """
220
+ { "cluster": {
221
+ "worker": ["127.0.0.1:2020"],
222
+ "chief": ["127.0.0.1:2021"]
223
+ },
224
+ "task": {"type": "chief", "index": 0}
225
+ }
226
+ """
227
+ test_dir = test_utils.get_tmp_dir()
228
+ tmp_file = os.path.join(test_dir,
229
+ 'easy_rec_hpo_test_%d.metric' % time.time())
230
+ hpo_util.save_eval_metrics('data/test/hpo_test/', tmp_file, False)
231
+ test_utils.clean_up(test_dir)
232
+
233
+
234
+ if __name__ == '__main__':
235
+ tf.test.main()