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.
- easy_cs_rec_custommodel-0.8.6.dist-info/LICENSE +203 -0
- easy_cs_rec_custommodel-0.8.6.dist-info/METADATA +48 -0
- easy_cs_rec_custommodel-0.8.6.dist-info/RECORD +336 -0
- easy_cs_rec_custommodel-0.8.6.dist-info/WHEEL +6 -0
- easy_cs_rec_custommodel-0.8.6.dist-info/top_level.txt +2 -0
- easy_rec/__init__.py +114 -0
- easy_rec/python/__init__.py +0 -0
- easy_rec/python/builders/__init__.py +0 -0
- easy_rec/python/builders/hyperparams_builder.py +78 -0
- easy_rec/python/builders/loss_builder.py +333 -0
- easy_rec/python/builders/optimizer_builder.py +211 -0
- easy_rec/python/builders/strategy_builder.py +44 -0
- easy_rec/python/compat/__init__.py +0 -0
- easy_rec/python/compat/adam_s.py +245 -0
- easy_rec/python/compat/array_ops.py +229 -0
- easy_rec/python/compat/dynamic_variable.py +542 -0
- easy_rec/python/compat/early_stopping.py +653 -0
- easy_rec/python/compat/embedding_ops.py +162 -0
- easy_rec/python/compat/embedding_parallel_saver.py +316 -0
- easy_rec/python/compat/estimator_train.py +116 -0
- easy_rec/python/compat/exporter.py +473 -0
- easy_rec/python/compat/feature_column/__init__.py +0 -0
- easy_rec/python/compat/feature_column/feature_column.py +3675 -0
- easy_rec/python/compat/feature_column/feature_column_v2.py +5233 -0
- easy_rec/python/compat/feature_column/sequence_feature_column.py +648 -0
- easy_rec/python/compat/feature_column/utils.py +154 -0
- easy_rec/python/compat/layers.py +329 -0
- easy_rec/python/compat/ops.py +14 -0
- easy_rec/python/compat/optimizers.py +619 -0
- easy_rec/python/compat/queues.py +311 -0
- easy_rec/python/compat/regularizers.py +208 -0
- easy_rec/python/compat/sok_optimizer.py +440 -0
- easy_rec/python/compat/sync_replicas_optimizer.py +528 -0
- easy_rec/python/compat/weight_decay_optimizers.py +475 -0
- easy_rec/python/core/__init__.py +0 -0
- easy_rec/python/core/easyrec_metrics/__init__.py +24 -0
- easy_rec/python/core/easyrec_metrics/distribute_metrics_impl_pai.py +3702 -0
- easy_rec/python/core/easyrec_metrics/distribute_metrics_impl_tf.py +3768 -0
- easy_rec/python/core/learning_schedules.py +228 -0
- easy_rec/python/core/metrics.py +402 -0
- easy_rec/python/core/sampler.py +844 -0
- easy_rec/python/eval.py +102 -0
- easy_rec/python/export.py +150 -0
- easy_rec/python/feature_column/__init__.py +0 -0
- easy_rec/python/feature_column/feature_column.py +664 -0
- easy_rec/python/feature_column/feature_group.py +89 -0
- easy_rec/python/hpo/__init__.py +0 -0
- easy_rec/python/hpo/emr_hpo.py +140 -0
- easy_rec/python/hpo/generate_hpo_sql.py +71 -0
- easy_rec/python/hpo/pai_hpo.py +297 -0
- easy_rec/python/inference/__init__.py +0 -0
- easy_rec/python/inference/csv_predictor.py +189 -0
- easy_rec/python/inference/hive_parquet_predictor.py +200 -0
- easy_rec/python/inference/hive_predictor.py +166 -0
- easy_rec/python/inference/odps_predictor.py +70 -0
- easy_rec/python/inference/parquet_predictor.py +147 -0
- easy_rec/python/inference/parquet_predictor_v2.py +147 -0
- easy_rec/python/inference/predictor.py +621 -0
- easy_rec/python/inference/processor/__init__.py +0 -0
- easy_rec/python/inference/processor/test.py +170 -0
- easy_rec/python/inference/vector_retrieve.py +124 -0
- easy_rec/python/input/__init__.py +0 -0
- easy_rec/python/input/batch_tfrecord_input.py +117 -0
- easy_rec/python/input/criteo_binary_reader.py +259 -0
- easy_rec/python/input/criteo_input.py +107 -0
- easy_rec/python/input/csv_input.py +175 -0
- easy_rec/python/input/csv_input_ex.py +72 -0
- easy_rec/python/input/csv_input_v2.py +68 -0
- easy_rec/python/input/datahub_input.py +320 -0
- easy_rec/python/input/dummy_input.py +58 -0
- easy_rec/python/input/hive_input.py +123 -0
- easy_rec/python/input/hive_parquet_input.py +140 -0
- easy_rec/python/input/hive_rtp_input.py +174 -0
- easy_rec/python/input/input.py +1064 -0
- easy_rec/python/input/kafka_dataset.py +144 -0
- easy_rec/python/input/kafka_input.py +235 -0
- easy_rec/python/input/load_parquet.py +317 -0
- easy_rec/python/input/odps_input.py +101 -0
- easy_rec/python/input/odps_input_v2.py +110 -0
- easy_rec/python/input/odps_input_v3.py +132 -0
- easy_rec/python/input/odps_rtp_input.py +187 -0
- easy_rec/python/input/odps_rtp_input_v2.py +104 -0
- easy_rec/python/input/parquet_input.py +397 -0
- easy_rec/python/input/parquet_input_v2.py +180 -0
- easy_rec/python/input/parquet_input_v3.py +203 -0
- easy_rec/python/input/rtp_input.py +225 -0
- easy_rec/python/input/rtp_input_v2.py +145 -0
- easy_rec/python/input/tfrecord_input.py +100 -0
- easy_rec/python/layers/__init__.py +0 -0
- easy_rec/python/layers/backbone.py +571 -0
- easy_rec/python/layers/capsule_layer.py +176 -0
- easy_rec/python/layers/cmbf.py +390 -0
- easy_rec/python/layers/common_layers.py +192 -0
- easy_rec/python/layers/dnn.py +87 -0
- easy_rec/python/layers/embed_input_layer.py +25 -0
- easy_rec/python/layers/fm.py +26 -0
- easy_rec/python/layers/input_layer.py +396 -0
- easy_rec/python/layers/keras/__init__.py +34 -0
- easy_rec/python/layers/keras/activation.py +114 -0
- easy_rec/python/layers/keras/attention.py +267 -0
- easy_rec/python/layers/keras/auxiliary_loss.py +47 -0
- easy_rec/python/layers/keras/blocks.py +262 -0
- easy_rec/python/layers/keras/bst.py +119 -0
- easy_rec/python/layers/keras/custom_ops.py +250 -0
- easy_rec/python/layers/keras/data_augment.py +133 -0
- easy_rec/python/layers/keras/din.py +67 -0
- easy_rec/python/layers/keras/einsum_dense.py +598 -0
- easy_rec/python/layers/keras/embedding.py +81 -0
- easy_rec/python/layers/keras/fibinet.py +251 -0
- easy_rec/python/layers/keras/interaction.py +416 -0
- easy_rec/python/layers/keras/layer_norm.py +364 -0
- easy_rec/python/layers/keras/mask_net.py +166 -0
- easy_rec/python/layers/keras/multi_head_attention.py +717 -0
- easy_rec/python/layers/keras/multi_task.py +125 -0
- easy_rec/python/layers/keras/numerical_embedding.py +376 -0
- easy_rec/python/layers/keras/ppnet.py +194 -0
- easy_rec/python/layers/keras/transformer.py +192 -0
- easy_rec/python/layers/layer_norm.py +51 -0
- easy_rec/python/layers/mmoe.py +83 -0
- easy_rec/python/layers/multihead_attention.py +162 -0
- easy_rec/python/layers/multihead_cross_attention.py +749 -0
- easy_rec/python/layers/senet.py +73 -0
- easy_rec/python/layers/seq_input_layer.py +134 -0
- easy_rec/python/layers/sequence_feature_layer.py +249 -0
- easy_rec/python/layers/uniter.py +301 -0
- easy_rec/python/layers/utils.py +248 -0
- easy_rec/python/layers/variational_dropout_layer.py +130 -0
- easy_rec/python/loss/__init__.py +0 -0
- easy_rec/python/loss/circle_loss.py +82 -0
- easy_rec/python/loss/contrastive_loss.py +79 -0
- easy_rec/python/loss/f1_reweight_loss.py +38 -0
- easy_rec/python/loss/focal_loss.py +93 -0
- easy_rec/python/loss/jrc_loss.py +128 -0
- easy_rec/python/loss/listwise_loss.py +161 -0
- easy_rec/python/loss/multi_similarity.py +68 -0
- easy_rec/python/loss/pairwise_loss.py +307 -0
- easy_rec/python/loss/softmax_loss_with_negative_mining.py +110 -0
- easy_rec/python/loss/zero_inflated_lognormal.py +76 -0
- easy_rec/python/main.py +878 -0
- easy_rec/python/model/__init__.py +0 -0
- easy_rec/python/model/autoint.py +73 -0
- easy_rec/python/model/cmbf.py +47 -0
- easy_rec/python/model/collaborative_metric_learning.py +182 -0
- easy_rec/python/model/custom_model.py +323 -0
- easy_rec/python/model/dat.py +138 -0
- easy_rec/python/model/dbmtl.py +116 -0
- easy_rec/python/model/dcn.py +70 -0
- easy_rec/python/model/deepfm.py +106 -0
- easy_rec/python/model/dlrm.py +73 -0
- easy_rec/python/model/dropoutnet.py +207 -0
- easy_rec/python/model/dssm.py +154 -0
- easy_rec/python/model/dssm_senet.py +143 -0
- easy_rec/python/model/dummy_model.py +48 -0
- easy_rec/python/model/easy_rec_estimator.py +739 -0
- easy_rec/python/model/easy_rec_model.py +467 -0
- easy_rec/python/model/esmm.py +242 -0
- easy_rec/python/model/fm.py +63 -0
- easy_rec/python/model/match_model.py +357 -0
- easy_rec/python/model/mind.py +445 -0
- easy_rec/python/model/mmoe.py +70 -0
- easy_rec/python/model/multi_task_model.py +303 -0
- easy_rec/python/model/multi_tower.py +62 -0
- easy_rec/python/model/multi_tower_bst.py +190 -0
- easy_rec/python/model/multi_tower_din.py +130 -0
- easy_rec/python/model/multi_tower_recall.py +68 -0
- easy_rec/python/model/pdn.py +203 -0
- easy_rec/python/model/ple.py +120 -0
- easy_rec/python/model/rank_model.py +485 -0
- easy_rec/python/model/rocket_launching.py +203 -0
- easy_rec/python/model/simple_multi_task.py +54 -0
- easy_rec/python/model/uniter.py +46 -0
- easy_rec/python/model/wide_and_deep.py +121 -0
- easy_rec/python/ops/1.12/incr_record.so +0 -0
- easy_rec/python/ops/1.12/kafka.so +0 -0
- easy_rec/python/ops/1.12/libcustom_ops.so +0 -0
- easy_rec/python/ops/1.12/libembed_op.so +0 -0
- easy_rec/python/ops/1.12/libhiredis.so.1.0.0 +0 -0
- easy_rec/python/ops/1.12/librdkafka++.so.1 +0 -0
- easy_rec/python/ops/1.12/librdkafka.so.1 +0 -0
- easy_rec/python/ops/1.12/libredis++.so +0 -0
- easy_rec/python/ops/1.12/libredis++.so.1 +0 -0
- easy_rec/python/ops/1.12/libredis++.so.1.2.3 +0 -0
- easy_rec/python/ops/1.12/libstr_avx_op.so +0 -0
- easy_rec/python/ops/1.12/libwrite_sparse_kv.so +0 -0
- easy_rec/python/ops/1.15/incr_record.so +0 -0
- easy_rec/python/ops/1.15/kafka.so +0 -0
- easy_rec/python/ops/1.15/libcustom_ops.so +0 -0
- easy_rec/python/ops/1.15/libembed_op.so +0 -0
- easy_rec/python/ops/1.15/libhiredis.so.1.0.0 +0 -0
- easy_rec/python/ops/1.15/librdkafka++.so +0 -0
- easy_rec/python/ops/1.15/librdkafka++.so.1 +0 -0
- easy_rec/python/ops/1.15/librdkafka.so +0 -0
- easy_rec/python/ops/1.15/librdkafka.so.1 +0 -0
- easy_rec/python/ops/1.15/libredis++.so.1 +0 -0
- easy_rec/python/ops/1.15/libstr_avx_op.so +0 -0
- easy_rec/python/ops/2.12/libcustom_ops.so +0 -0
- easy_rec/python/ops/2.12/libload_embed.so +0 -0
- easy_rec/python/ops/2.12/libstr_avx_op.so +0 -0
- easy_rec/python/ops/__init__.py +0 -0
- easy_rec/python/ops/gen_kafka_ops.py +193 -0
- easy_rec/python/ops/gen_str_avx_op.py +28 -0
- easy_rec/python/ops/incr_record.py +30 -0
- easy_rec/python/predict.py +170 -0
- easy_rec/python/protos/__init__.py +0 -0
- easy_rec/python/protos/autoint_pb2.py +122 -0
- easy_rec/python/protos/backbone_pb2.py +1416 -0
- easy_rec/python/protos/cmbf_pb2.py +435 -0
- easy_rec/python/protos/collaborative_metric_learning_pb2.py +252 -0
- easy_rec/python/protos/custom_model_pb2.py +57 -0
- easy_rec/python/protos/dat_pb2.py +262 -0
- easy_rec/python/protos/data_source_pb2.py +422 -0
- easy_rec/python/protos/dataset_pb2.py +1920 -0
- easy_rec/python/protos/dbmtl_pb2.py +191 -0
- easy_rec/python/protos/dcn_pb2.py +197 -0
- easy_rec/python/protos/deepfm_pb2.py +163 -0
- easy_rec/python/protos/dlrm_pb2.py +163 -0
- easy_rec/python/protos/dnn_pb2.py +329 -0
- easy_rec/python/protos/dropoutnet_pb2.py +239 -0
- easy_rec/python/protos/dssm_pb2.py +262 -0
- easy_rec/python/protos/dssm_senet_pb2.py +282 -0
- easy_rec/python/protos/easy_rec_model_pb2.py +1672 -0
- easy_rec/python/protos/esmm_pb2.py +133 -0
- easy_rec/python/protos/eval_pb2.py +930 -0
- easy_rec/python/protos/export_pb2.py +379 -0
- easy_rec/python/protos/feature_config_pb2.py +1359 -0
- easy_rec/python/protos/fm_pb2.py +90 -0
- easy_rec/python/protos/hive_config_pb2.py +138 -0
- easy_rec/python/protos/hyperparams_pb2.py +624 -0
- easy_rec/python/protos/keras_layer_pb2.py +692 -0
- easy_rec/python/protos/layer_pb2.py +1936 -0
- easy_rec/python/protos/loss_pb2.py +1713 -0
- easy_rec/python/protos/mind_pb2.py +497 -0
- easy_rec/python/protos/mmoe_pb2.py +215 -0
- easy_rec/python/protos/multi_tower_pb2.py +295 -0
- easy_rec/python/protos/multi_tower_recall_pb2.py +198 -0
- easy_rec/python/protos/optimizer_pb2.py +2017 -0
- easy_rec/python/protos/pdn_pb2.py +293 -0
- easy_rec/python/protos/pipeline_pb2.py +516 -0
- easy_rec/python/protos/ple_pb2.py +231 -0
- easy_rec/python/protos/predict_pb2.py +1140 -0
- easy_rec/python/protos/rocket_launching_pb2.py +169 -0
- easy_rec/python/protos/seq_encoder_pb2.py +1084 -0
- easy_rec/python/protos/simi_pb2.py +54 -0
- easy_rec/python/protos/simple_multi_task_pb2.py +97 -0
- easy_rec/python/protos/tf_predict_pb2.py +630 -0
- easy_rec/python/protos/tower_pb2.py +661 -0
- easy_rec/python/protos/train_pb2.py +1197 -0
- easy_rec/python/protos/uniter_pb2.py +307 -0
- easy_rec/python/protos/variational_dropout_pb2.py +91 -0
- easy_rec/python/protos/wide_and_deep_pb2.py +131 -0
- easy_rec/python/test/__init__.py +0 -0
- easy_rec/python/test/csv_input_test.py +340 -0
- easy_rec/python/test/custom_early_stop_func.py +19 -0
- easy_rec/python/test/dh_local_run.py +104 -0
- easy_rec/python/test/embed_test.py +155 -0
- easy_rec/python/test/emr_run.py +119 -0
- easy_rec/python/test/eval_metric_test.py +107 -0
- easy_rec/python/test/excel_convert_test.py +64 -0
- easy_rec/python/test/export_test.py +513 -0
- easy_rec/python/test/fg_test.py +70 -0
- easy_rec/python/test/hive_input_test.py +311 -0
- easy_rec/python/test/hpo_test.py +235 -0
- easy_rec/python/test/kafka_test.py +373 -0
- easy_rec/python/test/local_incr_test.py +122 -0
- easy_rec/python/test/loss_test.py +110 -0
- easy_rec/python/test/odps_command.py +61 -0
- easy_rec/python/test/odps_local_run.py +86 -0
- easy_rec/python/test/odps_run.py +254 -0
- easy_rec/python/test/odps_test_cls.py +39 -0
- easy_rec/python/test/odps_test_prepare.py +198 -0
- easy_rec/python/test/odps_test_util.py +237 -0
- easy_rec/python/test/pre_check_test.py +54 -0
- easy_rec/python/test/predictor_test.py +394 -0
- easy_rec/python/test/rtp_convert_test.py +133 -0
- easy_rec/python/test/run.py +138 -0
- easy_rec/python/test/train_eval_test.py +1299 -0
- easy_rec/python/test/util_test.py +85 -0
- easy_rec/python/test/zero_inflated_lognormal_test.py +53 -0
- easy_rec/python/tools/__init__.py +0 -0
- easy_rec/python/tools/add_boundaries_to_config.py +67 -0
- easy_rec/python/tools/add_feature_info_to_config.py +145 -0
- easy_rec/python/tools/convert_config_format.py +48 -0
- easy_rec/python/tools/convert_rtp_data.py +79 -0
- easy_rec/python/tools/convert_rtp_fg.py +106 -0
- easy_rec/python/tools/create_config_from_excel.py +427 -0
- easy_rec/python/tools/criteo/__init__.py +0 -0
- easy_rec/python/tools/criteo/convert_data.py +157 -0
- easy_rec/python/tools/edit_lookup_graph.py +134 -0
- easy_rec/python/tools/faiss_index_pai.py +116 -0
- easy_rec/python/tools/feature_selection.py +316 -0
- easy_rec/python/tools/hit_rate_ds.py +223 -0
- easy_rec/python/tools/hit_rate_pai.py +138 -0
- easy_rec/python/tools/pre_check.py +120 -0
- easy_rec/python/tools/predict_and_chk.py +111 -0
- easy_rec/python/tools/read_kafka.py +55 -0
- easy_rec/python/tools/split_model_pai.py +286 -0
- easy_rec/python/tools/split_pdn_model_pai.py +272 -0
- easy_rec/python/tools/test_saved_model.py +80 -0
- easy_rec/python/tools/view_saved_model.py +39 -0
- easy_rec/python/tools/write_kafka.py +65 -0
- easy_rec/python/train_eval.py +325 -0
- easy_rec/python/utils/__init__.py +15 -0
- easy_rec/python/utils/activation.py +120 -0
- easy_rec/python/utils/check_utils.py +87 -0
- easy_rec/python/utils/compat.py +14 -0
- easy_rec/python/utils/config_util.py +652 -0
- easy_rec/python/utils/constant.py +43 -0
- easy_rec/python/utils/convert_rtp_fg.py +616 -0
- easy_rec/python/utils/dag.py +192 -0
- easy_rec/python/utils/distribution_utils.py +268 -0
- easy_rec/python/utils/ds_util.py +65 -0
- easy_rec/python/utils/embedding_utils.py +73 -0
- easy_rec/python/utils/estimator_utils.py +1036 -0
- easy_rec/python/utils/export_big_model.py +630 -0
- easy_rec/python/utils/expr_util.py +118 -0
- easy_rec/python/utils/fg_util.py +53 -0
- easy_rec/python/utils/hit_rate_utils.py +220 -0
- easy_rec/python/utils/hive_utils.py +183 -0
- easy_rec/python/utils/hpo_util.py +137 -0
- easy_rec/python/utils/hvd_utils.py +56 -0
- easy_rec/python/utils/input_utils.py +108 -0
- easy_rec/python/utils/io_util.py +282 -0
- easy_rec/python/utils/load_class.py +249 -0
- easy_rec/python/utils/meta_graph_editor.py +941 -0
- easy_rec/python/utils/multi_optimizer.py +62 -0
- easy_rec/python/utils/numpy_utils.py +18 -0
- easy_rec/python/utils/odps_util.py +79 -0
- easy_rec/python/utils/pai_util.py +86 -0
- easy_rec/python/utils/proto_util.py +90 -0
- easy_rec/python/utils/restore_filter.py +89 -0
- easy_rec/python/utils/shape_utils.py +432 -0
- easy_rec/python/utils/static_shape.py +71 -0
- easy_rec/python/utils/test_utils.py +866 -0
- easy_rec/python/utils/tf_utils.py +56 -0
- easy_rec/version.py +4 -0
- test/__init__.py +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# -*- encoding:utf-8 -*-
|
|
2
|
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import logging
|
|
6
|
+
import os
|
|
7
|
+
import shutil
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
import tensorflow as tf
|
|
11
|
+
|
|
12
|
+
from easy_rec.python.test.odps_command import OdpsCommand
|
|
13
|
+
from easy_rec.python.test.odps_test_prepare import prepare
|
|
14
|
+
from easy_rec.python.test.odps_test_util import OdpsOSSConfig
|
|
15
|
+
from easy_rec.python.test.odps_test_util import delete_oss_path
|
|
16
|
+
from easy_rec.python.test.odps_test_util import get_oss_bucket
|
|
17
|
+
from easy_rec.python.utils import test_utils
|
|
18
|
+
|
|
19
|
+
logging.basicConfig(
|
|
20
|
+
level=logging.INFO, format='[%(asctime)s][%(levelname)s] %(message)s')
|
|
21
|
+
|
|
22
|
+
odps_oss_config = OdpsOSSConfig(script_path='./samples/emr_script')
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TestPipelineLocal(tf.test.TestCase):
|
|
26
|
+
"""Train eval test on emr."""
|
|
27
|
+
|
|
28
|
+
def setUp(self):
|
|
29
|
+
logging.info('Testing %s.%s' % (type(self).__name__, self._testMethodName))
|
|
30
|
+
self._success = True
|
|
31
|
+
self._test_dir = test_utils.get_tmp_dir()
|
|
32
|
+
|
|
33
|
+
def tearDown(self):
|
|
34
|
+
if self._success:
|
|
35
|
+
shutil.rmtree(self._test_dir)
|
|
36
|
+
|
|
37
|
+
def test_deepfm_local_with_common_io(self):
|
|
38
|
+
start = [
|
|
39
|
+
'deep_fm/create_external_deepfm_table.sql',
|
|
40
|
+
'deep_fm/create_inner_deepfm_table.sql'
|
|
41
|
+
]
|
|
42
|
+
end = ['deep_fm/drop_table.sql']
|
|
43
|
+
odps_cmd = OdpsCommand(odps_oss_config)
|
|
44
|
+
odps_cmd.run_list(start)
|
|
45
|
+
self._success = test_utils.test_single_train_eval(
|
|
46
|
+
'%s/configs/deepfm.config' % odps_oss_config.temp_dir, self._test_dir)
|
|
47
|
+
odps_cmd.run_list(end)
|
|
48
|
+
self.assertTrue(self._success)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == '__main__':
|
|
52
|
+
parser = argparse.ArgumentParser()
|
|
53
|
+
parser.add_argument(
|
|
54
|
+
'--odps_config', type=str, default=None, help='odps config path')
|
|
55
|
+
parser.add_argument(
|
|
56
|
+
'--oss_config', type=str, default=None, help='ossutilconfig path')
|
|
57
|
+
parser.add_argument(
|
|
58
|
+
'--bucket_name', type=str, default=None, help='test oss bucket name')
|
|
59
|
+
parser.add_argument('--arn', type=str, default=None, help='oss rolearn')
|
|
60
|
+
parser.add_argument(
|
|
61
|
+
'--odpscmd', type=str, default='odpscmd', help='odpscmd path')
|
|
62
|
+
args, unknown_args = parser.parse_known_args()
|
|
63
|
+
sys.argv = [sys.argv[0]]
|
|
64
|
+
for unk_arg in unknown_args:
|
|
65
|
+
sys.argv.append(unk_arg)
|
|
66
|
+
|
|
67
|
+
if args.odps_config:
|
|
68
|
+
odps_oss_config.load_odps_config(args.odps_config)
|
|
69
|
+
os.environ['ODPS_CONFIG_FILE_PATH'] = args.odps_config
|
|
70
|
+
if args.oss_config:
|
|
71
|
+
odps_oss_config.load_oss_config(args.oss_config)
|
|
72
|
+
if args.odpscmd:
|
|
73
|
+
odps_oss_config.odpscmd_path = args.odpscmd
|
|
74
|
+
if args.arn:
|
|
75
|
+
odps_oss_config.arn = args.arn
|
|
76
|
+
if args.bucket_name:
|
|
77
|
+
odps_oss_config.bucket_name = args.bucket_name
|
|
78
|
+
|
|
79
|
+
prepare(odps_oss_config)
|
|
80
|
+
tf.test.main()
|
|
81
|
+
# delete oss path
|
|
82
|
+
bucket = get_oss_bucket(odps_oss_config.oss_key, odps_oss_config.oss_secret,
|
|
83
|
+
odps_oss_config.endpoint, odps_oss_config.bucket_name)
|
|
84
|
+
delete_oss_path(bucket, odps_oss_config.exp_dir, odps_oss_config.bucket_name)
|
|
85
|
+
# delete tmp
|
|
86
|
+
shutil.rmtree(odps_oss_config.temp_dir)
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# -*- encoding:utf-8 -*-
|
|
2
|
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import logging
|
|
6
|
+
import os
|
|
7
|
+
import shutil
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
import oss2
|
|
11
|
+
import tensorflow as tf
|
|
12
|
+
|
|
13
|
+
from easy_rec.python.test.odps_test_cls import OdpsTest
|
|
14
|
+
from easy_rec.python.test.odps_test_prepare import prepare
|
|
15
|
+
from easy_rec.python.test.odps_test_util import OdpsOSSConfig
|
|
16
|
+
from easy_rec.python.test.odps_test_util import delete_oss_path
|
|
17
|
+
from easy_rec.python.test.odps_test_util import get_oss_bucket
|
|
18
|
+
from easy_rec.python.utils import config_util
|
|
19
|
+
|
|
20
|
+
logging.basicConfig(
|
|
21
|
+
level=logging.INFO, format='[%(asctime)s][%(levelname)s] %(message)s')
|
|
22
|
+
|
|
23
|
+
odps_oss_config = OdpsOSSConfig()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class TestPipelineOnOdps(tf.test.TestCase):
|
|
27
|
+
"""train eval export test on odps."""
|
|
28
|
+
|
|
29
|
+
def test_deepfm(self):
|
|
30
|
+
start_files = ['deep_fm/create_inner_deepfm_table.sql']
|
|
31
|
+
test_files = [
|
|
32
|
+
'deep_fm/train_deepfm_model.sql', 'deep_fm/eval_deepfm.sql',
|
|
33
|
+
'deep_fm/export_deepfm.sql', 'deep_fm/predict_deepfm.sql',
|
|
34
|
+
'deep_fm/export_rtp_ckpt.sql'
|
|
35
|
+
]
|
|
36
|
+
end_file = ['deep_fm/drop_table.sql']
|
|
37
|
+
|
|
38
|
+
tot = OdpsTest(start_files, test_files, end_file, odps_oss_config)
|
|
39
|
+
tot.start_test()
|
|
40
|
+
tot.drop_table()
|
|
41
|
+
|
|
42
|
+
def test_mmoe(self):
|
|
43
|
+
start_files = ['mmoe/create_inner_mmoe_table.sql']
|
|
44
|
+
test_files = [
|
|
45
|
+
'mmoe/train_mmoe_model.sql',
|
|
46
|
+
'mmoe/eval_mmoe.sql',
|
|
47
|
+
'mmoe/export_mmoe.sql',
|
|
48
|
+
'mmoe/predict_mmoe.sql',
|
|
49
|
+
]
|
|
50
|
+
end_file = ['mmoe/drop_mmoe_table.sql']
|
|
51
|
+
tot = OdpsTest(start_files, test_files, end_file, odps_oss_config)
|
|
52
|
+
tot.start_test()
|
|
53
|
+
tot.drop_table()
|
|
54
|
+
|
|
55
|
+
def test_dssm(self):
|
|
56
|
+
start_files = [
|
|
57
|
+
'dssm/create_inner_dssm_table.sql',
|
|
58
|
+
]
|
|
59
|
+
test_files = [
|
|
60
|
+
'dssm/train_dssm_model.sql',
|
|
61
|
+
'dssm/eval_dssm.sql',
|
|
62
|
+
'dssm/export_dssm.sql',
|
|
63
|
+
'dssm/predict_dssm.sql',
|
|
64
|
+
]
|
|
65
|
+
end_file = [
|
|
66
|
+
'dssm/drop_dssm_table.sql',
|
|
67
|
+
]
|
|
68
|
+
tot = OdpsTest(start_files, test_files, end_file, odps_oss_config)
|
|
69
|
+
tot.start_test()
|
|
70
|
+
tot.drop_table()
|
|
71
|
+
|
|
72
|
+
def test_multi_tower(self):
|
|
73
|
+
start_files = ['multi_tower/create_inner_multi_tower_table.sql']
|
|
74
|
+
test_files = [
|
|
75
|
+
'multi_tower/train_multil_tower_din_model.sql',
|
|
76
|
+
'multi_tower/train_multil_tower_bst_model.sql',
|
|
77
|
+
'multi_tower/eval_multil_tower.sql',
|
|
78
|
+
'multi_tower/export_multil_tower.sql',
|
|
79
|
+
'multi_tower/export_again_multi_tower.sql',
|
|
80
|
+
'multi_tower/predict_multil_tower.sql',
|
|
81
|
+
]
|
|
82
|
+
end_file = ['multi_tower/drop_multil_tower_table.sql']
|
|
83
|
+
tot = OdpsTest(start_files, test_files, end_file, odps_oss_config)
|
|
84
|
+
tot.start_test()
|
|
85
|
+
tot.drop_table()
|
|
86
|
+
|
|
87
|
+
def test_other(self):
|
|
88
|
+
start_files = ['deep_fm/create_inner_deepfm_table.sql']
|
|
89
|
+
test_files = [
|
|
90
|
+
# 'other_test/test_train_gpuRequired_mirrored', # 线上报错,
|
|
91
|
+
# 'other_test/test_train_distribute_strategy_collective', # 线上报错,
|
|
92
|
+
'other_test/test_train_hpo_with_evaluator.sql',
|
|
93
|
+
# 'other_test/test_train_version.sql',
|
|
94
|
+
# 'other_test/test_train_distribute_strategy_ess.sql',
|
|
95
|
+
'other_test/test_train_before_export.sql',
|
|
96
|
+
'other_test/test_eval_checkpoint_path.sql',
|
|
97
|
+
'other_test/test_export_checkpoint_path.sql',
|
|
98
|
+
'other_test/test_export_update_model_dir.sql',
|
|
99
|
+
'other_test/test_predict_selected_cols.sql',
|
|
100
|
+
]
|
|
101
|
+
end_file = ['other_test/drop_table.sql']
|
|
102
|
+
tot = OdpsTest(start_files, test_files, end_file, odps_oss_config)
|
|
103
|
+
tot.start_test()
|
|
104
|
+
tot.drop_table()
|
|
105
|
+
|
|
106
|
+
def test_best_exporter(self):
|
|
107
|
+
start_files = ['deep_fm/create_inner_deepfm_table.sql']
|
|
108
|
+
test_files = [
|
|
109
|
+
'other_test/test_train_best_export.sql',
|
|
110
|
+
]
|
|
111
|
+
end_file = ['other_test/drop_table.sql']
|
|
112
|
+
tot = OdpsTest(start_files, test_files, end_file, odps_oss_config)
|
|
113
|
+
tot.start_test()
|
|
114
|
+
config_path = os.path.join(
|
|
115
|
+
odps_oss_config.temp_dir,
|
|
116
|
+
'configs/dwd_avazu_ctr_deepmodel_ext_best_export.config')
|
|
117
|
+
config = config_util.get_configs_from_pipeline_file(config_path)
|
|
118
|
+
model_dir = config.model_dir
|
|
119
|
+
logging.info('raw model_dir = %s' % model_dir)
|
|
120
|
+
if model_dir.startswith('oss://'):
|
|
121
|
+
spos = model_dir.index('/', len('oss://') + 1) + 1
|
|
122
|
+
model_dir = model_dir[spos:]
|
|
123
|
+
logging.info('stripped model_dir = %s' % model_dir)
|
|
124
|
+
|
|
125
|
+
bucket = get_oss_bucket(odps_oss_config.oss_key, odps_oss_config.oss_secret,
|
|
126
|
+
odps_oss_config.endpoint,
|
|
127
|
+
odps_oss_config.bucket_name)
|
|
128
|
+
best_ckpt_prefix = os.path.join(model_dir, 'best_ckpt/model.ckpt')
|
|
129
|
+
best_ckpts = [
|
|
130
|
+
x.key
|
|
131
|
+
for x in oss2.ObjectIterator(bucket, prefix=best_ckpt_prefix)
|
|
132
|
+
if x.key.endswith('.meta')
|
|
133
|
+
]
|
|
134
|
+
logging.info('best ckpts: %s' % str(best_ckpts))
|
|
135
|
+
assert len(best_ckpts) <= 2, 'too many best ckpts: %s' % str(best_ckpts)
|
|
136
|
+
best_export_prefix = os.path.join(model_dir, 'export/best/')
|
|
137
|
+
best_exports = [
|
|
138
|
+
x.key
|
|
139
|
+
for x in oss2.ObjectIterator(bucket, prefix=best_export_prefix)
|
|
140
|
+
if x.key.endswith('/saved_model.pb')
|
|
141
|
+
]
|
|
142
|
+
logging.info('best exports: %s' % str(best_exports))
|
|
143
|
+
assert len(
|
|
144
|
+
best_exports) <= 2, 'too many best exports: %s' % str(best_exports)
|
|
145
|
+
return True
|
|
146
|
+
|
|
147
|
+
def test_embedding_variable(self):
|
|
148
|
+
start_files = [
|
|
149
|
+
'embedding_variable/create_table.sql',
|
|
150
|
+
]
|
|
151
|
+
test_files = [
|
|
152
|
+
'embedding_variable/train.sql', 'embedding_variable/train_work_que.sql',
|
|
153
|
+
'embedding_variable/export.sql'
|
|
154
|
+
]
|
|
155
|
+
end_file = ['embedding_variable/drop_table.sql']
|
|
156
|
+
tot = OdpsTest(start_files, test_files, end_file, odps_oss_config)
|
|
157
|
+
tot.start_test()
|
|
158
|
+
tot.drop_table()
|
|
159
|
+
|
|
160
|
+
def test_multi_value_export(self):
|
|
161
|
+
start_files = ['multi_value/create_inner_multi_value_table.sql']
|
|
162
|
+
test_files = ['multi_value/train_multi_tower_model.sql']
|
|
163
|
+
end_file = ['multi_value/drop_table.sql']
|
|
164
|
+
tot = OdpsTest(start_files, test_files, end_file, odps_oss_config)
|
|
165
|
+
tot.start_test()
|
|
166
|
+
tot.drop_table()
|
|
167
|
+
|
|
168
|
+
def test_boundary_test(self):
|
|
169
|
+
start_files = [
|
|
170
|
+
'boundary/create_inner_boundary_table.sql',
|
|
171
|
+
]
|
|
172
|
+
test_files = [
|
|
173
|
+
'boundary/train_multi_tower_model.sql',
|
|
174
|
+
'boundary/finetune_multi_tower_model.sql',
|
|
175
|
+
'boundary/finetune_multi_tower_conti.sql', 'boundary/train_compat.sql'
|
|
176
|
+
]
|
|
177
|
+
end_file = ['boundary/drop_table.sql']
|
|
178
|
+
tot = OdpsTest(start_files, test_files, end_file, odps_oss_config)
|
|
179
|
+
tot.start_test()
|
|
180
|
+
tot.drop_table()
|
|
181
|
+
|
|
182
|
+
def test_vector_retrieve(self):
|
|
183
|
+
start_files = ['vector_retrieve/create_inner_vector_table.sql']
|
|
184
|
+
test_files = ['vector_retrieve/run_vector_retrieve.sql']
|
|
185
|
+
end_file = ['vector_retrieve/drop_table.sql']
|
|
186
|
+
tot = OdpsTest(start_files, test_files, end_file, odps_oss_config)
|
|
187
|
+
tot.start_test()
|
|
188
|
+
tot.drop_table()
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
if __name__ == '__main__':
|
|
192
|
+
parser = argparse.ArgumentParser()
|
|
193
|
+
parser.add_argument(
|
|
194
|
+
'--odps_config', type=str, default=None, help='odps config path')
|
|
195
|
+
parser.add_argument(
|
|
196
|
+
'--oss_config', type=str, default=None, help='ossutilconfig path')
|
|
197
|
+
parser.add_argument(
|
|
198
|
+
'--bucket_name', type=str, default=None, help='test oss bucket name')
|
|
199
|
+
parser.add_argument('--arn', type=str, default=None, help='oss rolearn')
|
|
200
|
+
parser.add_argument(
|
|
201
|
+
'--odpscmd', type=str, default='odpscmd', help='odpscmd path')
|
|
202
|
+
parser.add_argument(
|
|
203
|
+
'--algo_name',
|
|
204
|
+
type=str,
|
|
205
|
+
default='easy_rec_ext',
|
|
206
|
+
help='whether use pai-tf 1.15')
|
|
207
|
+
parser.add_argument(
|
|
208
|
+
'--algo_project', type=str, default=None, help='algo project name')
|
|
209
|
+
parser.add_argument(
|
|
210
|
+
'--algo_res_project',
|
|
211
|
+
type=str,
|
|
212
|
+
default=None,
|
|
213
|
+
help='algo resource project name')
|
|
214
|
+
parser.add_argument(
|
|
215
|
+
'--algo_version', type=str, default=None, help='algo version')
|
|
216
|
+
parser.add_argument(
|
|
217
|
+
'--is_outer',
|
|
218
|
+
type=int,
|
|
219
|
+
default=1,
|
|
220
|
+
help='is outer pai or inner pai, the arguments are differed slightly due to history reasons'
|
|
221
|
+
)
|
|
222
|
+
args, unknown_args = parser.parse_known_args()
|
|
223
|
+
sys.argv = [sys.argv[0]]
|
|
224
|
+
for unk_arg in unknown_args:
|
|
225
|
+
sys.argv.append(unk_arg)
|
|
226
|
+
|
|
227
|
+
if args.odps_config:
|
|
228
|
+
odps_oss_config.load_odps_config(args.odps_config)
|
|
229
|
+
if args.oss_config:
|
|
230
|
+
odps_oss_config.load_oss_config(args.oss_config)
|
|
231
|
+
if args.odpscmd:
|
|
232
|
+
odps_oss_config.odpscmd_path = args.odpscmd
|
|
233
|
+
if args.algo_project:
|
|
234
|
+
odps_oss_config.algo_project = args.algo_project
|
|
235
|
+
if args.algo_res_project:
|
|
236
|
+
odps_oss_config.algo_res_project = args.algo_res_project
|
|
237
|
+
if args.algo_version:
|
|
238
|
+
odps_oss_config.algo_version = args.algo_version
|
|
239
|
+
algo_names = ['easy_rec_ext15', 'easy_rec_ext']
|
|
240
|
+
assert args.algo_name in algo_names, 'algo_name must be oneof: %s' % (
|
|
241
|
+
','.join(algo_names))
|
|
242
|
+
odps_oss_config.algo_name = args.algo_name
|
|
243
|
+
if args.arn:
|
|
244
|
+
odps_oss_config.arn = args.arn
|
|
245
|
+
if args.bucket_name:
|
|
246
|
+
odps_oss_config.bucket_name = args.bucket_name
|
|
247
|
+
odps_oss_config.is_outer = args.is_outer
|
|
248
|
+
|
|
249
|
+
prepare(odps_oss_config)
|
|
250
|
+
tf.test.main()
|
|
251
|
+
bucket = get_oss_bucket(odps_oss_config.oss_key, odps_oss_config.oss_secret,
|
|
252
|
+
odps_oss_config.endpoint, odps_oss_config.bucket_name)
|
|
253
|
+
delete_oss_path(bucket, odps_oss_config.exp_dir, odps_oss_config.bucket_name)
|
|
254
|
+
shutil.rmtree(odps_oss_config.temp_dir)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# -*- encoding:utf-8 -*-
|
|
2
|
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
3
|
+
|
|
4
|
+
from multiprocessing import Process
|
|
5
|
+
|
|
6
|
+
from easy_rec.python.test.odps_command import OdpsCommand
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class OdpsTest(Process):
|
|
10
|
+
"""Test easyrec on odps."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, start_files, test_files, end_file, odps_oss_config):
|
|
13
|
+
"""Init odps test instance.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
start_files: prepare sql files, to create tables
|
|
17
|
+
test_files: actual test sql files, such as train/eval/export
|
|
18
|
+
end_file: drop table sql files
|
|
19
|
+
odps_oss_config: easy_rec.python.test.odps_test_util.OdpsOSSConfig
|
|
20
|
+
"""
|
|
21
|
+
super(OdpsTest, self).__init__()
|
|
22
|
+
self.start_files = start_files
|
|
23
|
+
self.test_files = test_files
|
|
24
|
+
self.end_file = end_file
|
|
25
|
+
|
|
26
|
+
self.odps = OdpsCommand(odps_oss_config)
|
|
27
|
+
self.init_table()
|
|
28
|
+
|
|
29
|
+
def init_table(self):
|
|
30
|
+
"""Init table for test."""
|
|
31
|
+
self.odps.run_list(self.start_files)
|
|
32
|
+
|
|
33
|
+
def start_test(self):
|
|
34
|
+
"""Exec every file in self.test_files."""
|
|
35
|
+
self.odps.run_list(self.test_files)
|
|
36
|
+
|
|
37
|
+
def drop_table(self):
|
|
38
|
+
"""Drop temporary tables."""
|
|
39
|
+
self.odps.run_list(self.end_file)
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# -*- encoding:utf-8 -*-
|
|
2
|
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
3
|
+
|
|
4
|
+
import glob
|
|
5
|
+
import logging
|
|
6
|
+
import os
|
|
7
|
+
import shutil
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
import oss2
|
|
11
|
+
|
|
12
|
+
from easy_rec.python.test.odps_test_util import OdpsOSSConfig
|
|
13
|
+
from easy_rec.python.test.odps_test_util import get_oss_bucket
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def download_data(ali_bucket, script_path):
|
|
17
|
+
"""Download data from alibaba bucket(readonly) to script_path.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
ali_bucket: alibaba bucket
|
|
21
|
+
script_path: down path
|
|
22
|
+
"""
|
|
23
|
+
if not os.path.exists(script_path):
|
|
24
|
+
raise '%s path is not exists' % script_path
|
|
25
|
+
if os.path.exists(os.path.join(script_path, 'test')):
|
|
26
|
+
shutil.rmtree(os.path.join(script_path, 'test'))
|
|
27
|
+
|
|
28
|
+
# download data from oss://${ali_bucket}/data/odps_test/
|
|
29
|
+
# to script_path/test_data
|
|
30
|
+
for obj in oss2.ObjectIterator(ali_bucket, prefix='data/odps_test/'):
|
|
31
|
+
obj_key = obj.key
|
|
32
|
+
tmp_oss_dir = os.path.split(obj_key)[0]
|
|
33
|
+
obj_path = os.path.join(script_path, tmp_oss_dir)
|
|
34
|
+
try:
|
|
35
|
+
os.makedirs(obj_path)
|
|
36
|
+
except Exception:
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
if obj_key.endswith('/'):
|
|
40
|
+
continue
|
|
41
|
+
|
|
42
|
+
dst_name = obj_key.replace('data/odps_test/', 'test_data/')
|
|
43
|
+
dst_path = os.path.join(script_path, dst_name)
|
|
44
|
+
dst_dir, _ = os.path.split(dst_path)
|
|
45
|
+
if not os.path.exists(dst_dir):
|
|
46
|
+
os.makedirs(dst_dir)
|
|
47
|
+
ali_bucket.get_object_to_file(obj_key, dst_path)
|
|
48
|
+
logging.info('down file oss://%s/%s to %s completed' %
|
|
49
|
+
(ali_bucket.bucket_name, obj_key, dst_path))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def merge_files(merge_dir, merge_out):
|
|
53
|
+
"""Merge files in merge_dir into merge_out.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
merge_dir: files of directory to merge.
|
|
57
|
+
merge_out: merged output file.
|
|
58
|
+
"""
|
|
59
|
+
input_files = list(glob.glob(merge_dir + '/*'))
|
|
60
|
+
logging.info('merge %s into %s' % (','.join(input_files), merge_out))
|
|
61
|
+
with open(merge_out, 'w') as fout:
|
|
62
|
+
for input_path in glob.glob(merge_dir + '/*'):
|
|
63
|
+
with open(input_path, 'r') as fin:
|
|
64
|
+
for line_str in fin:
|
|
65
|
+
fout.write(line_str)
|
|
66
|
+
return merge_out
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def change_files(odps_oss_config, file_path):
|
|
70
|
+
"""Update params in config files.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
odps_oss_config: odps oss test config
|
|
74
|
+
file_path: config file path
|
|
75
|
+
"""
|
|
76
|
+
# skip temporary file
|
|
77
|
+
if len(file_path) > 3 and file_path[-4:-1] == '.sw':
|
|
78
|
+
return
|
|
79
|
+
|
|
80
|
+
endpoint = odps_oss_config.endpoint.replace('http://', '')
|
|
81
|
+
# endpoint_internal = endpoint.replace('.aliyuncs.com',
|
|
82
|
+
# '-internal.aliyuncs.com')
|
|
83
|
+
|
|
84
|
+
test_data_dir = os.path.join(odps_oss_config.temp_dir, 'test_data')
|
|
85
|
+
|
|
86
|
+
with open(file_path, 'r') as fin:
|
|
87
|
+
lines = fin.readlines()
|
|
88
|
+
|
|
89
|
+
with open(file_path, 'w') as fw:
|
|
90
|
+
for line in lines:
|
|
91
|
+
if 'pai' in line.lower() and 'easy_rec_ext' in line.lower():
|
|
92
|
+
line = 'pai -name ' + odps_oss_config.algo_name + '\n'
|
|
93
|
+
if odps_oss_config.algo_project:
|
|
94
|
+
line += '-project=%s\n' % odps_oss_config.algo_project
|
|
95
|
+
if odps_oss_config.algo_res_project:
|
|
96
|
+
line += '-Dres_project=%s\n' % odps_oss_config.algo_res_project
|
|
97
|
+
if odps_oss_config.algo_version:
|
|
98
|
+
line += '-Dversion=%s\n' % odps_oss_config.algo_version
|
|
99
|
+
|
|
100
|
+
if odps_oss_config.is_outer:
|
|
101
|
+
line = line.replace('{OSS_BUCKET_NAME}', odps_oss_config.bucket_name)
|
|
102
|
+
line = line.replace('{ROLEARN}', odps_oss_config.arn)
|
|
103
|
+
line = line.replace('{OSS_ENDPOINT}', endpoint)
|
|
104
|
+
else:
|
|
105
|
+
tmp_e = odps_oss_config.endpoint
|
|
106
|
+
# tmp_e = tmp_e.replace('oss-cn-', 'cn-')
|
|
107
|
+
# tmp_e = tmp_e.replace('.aliyuncs.com', '.oss-internal.aliyun-inc.com')
|
|
108
|
+
if '-Dbuckets=' in line:
|
|
109
|
+
line = '-Dbuckets=oss://%s/?role_arn=%s&host=%s\n' % (
|
|
110
|
+
odps_oss_config.bucket_name, odps_oss_config.arn, tmp_e)
|
|
111
|
+
elif '-Darn=' in line or '-DossHost' in line:
|
|
112
|
+
continue
|
|
113
|
+
line = line.replace('{OSS_BUCKET_NAME}', odps_oss_config.bucket_name)
|
|
114
|
+
|
|
115
|
+
line = line.replace('{TIME_STAMP}', str(odps_oss_config.time_stamp))
|
|
116
|
+
|
|
117
|
+
if 'tunnel upload' in line:
|
|
118
|
+
line = line.replace('{TEST_DATA_DIR}', test_data_dir)
|
|
119
|
+
# merge files
|
|
120
|
+
toks = [x for x in line.split(' ') if x != '']
|
|
121
|
+
merge_path = toks[2]
|
|
122
|
+
merge_dir = '_'.join(merge_path.split('_')[:-1])
|
|
123
|
+
if not os.path.exists(merge_path):
|
|
124
|
+
merge_files(merge_dir, merge_path)
|
|
125
|
+
|
|
126
|
+
# for emr odps test only
|
|
127
|
+
line = line.replace('{TEMP_DIR}', str(odps_oss_config.temp_dir))
|
|
128
|
+
line = line.replace('{ODPS_PROJ_NAME}', odps_oss_config.project_name)
|
|
129
|
+
line = line.replace('{EXP_NAME}', odps_oss_config.exp_dir)
|
|
130
|
+
fw.write(line)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def put_data_to_bucket(odps_oss_config):
|
|
134
|
+
"""Upload test data and configs to my_bucket.
|
|
135
|
+
|
|
136
|
+
Args:
|
|
137
|
+
odps_oss_config: odps oss config obj
|
|
138
|
+
"""
|
|
139
|
+
test_bucket = get_oss_bucket(odps_oss_config.oss_key,
|
|
140
|
+
odps_oss_config.oss_secret,
|
|
141
|
+
odps_oss_config.endpoint,
|
|
142
|
+
odps_oss_config.bucket_name)
|
|
143
|
+
for sub_dir in ['configs']:
|
|
144
|
+
for root, dirs, files in os.walk(
|
|
145
|
+
os.path.join(odps_oss_config.temp_dir, sub_dir)):
|
|
146
|
+
for one_file in files:
|
|
147
|
+
file_path = os.path.join(root, one_file)
|
|
148
|
+
obj_path = file_path.split(sub_dir + '/')[1]
|
|
149
|
+
dst_path = os.path.join(odps_oss_config.exp_dir, sub_dir, obj_path)
|
|
150
|
+
test_bucket.put_object_from_file(dst_path, file_path)
|
|
151
|
+
logging.info('put %s to oss://%s/%s' %
|
|
152
|
+
(file_path, odps_oss_config.bucket_name, dst_path))
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def prepare(odps_oss_config):
|
|
156
|
+
logging.info('temp_dir = %s' % odps_oss_config.temp_dir)
|
|
157
|
+
ali_bucket = get_oss_bucket(odps_oss_config.ali_oss_key,
|
|
158
|
+
odps_oss_config.ali_oss_secret,
|
|
159
|
+
odps_oss_config.ali_bucket_endpoint,
|
|
160
|
+
odps_oss_config.ali_bucket_name)
|
|
161
|
+
shutil.copytree(odps_oss_config.script_path, odps_oss_config.temp_dir)
|
|
162
|
+
logging.info('start down data')
|
|
163
|
+
download_data(ali_bucket, odps_oss_config.temp_dir)
|
|
164
|
+
logging.info('down data completed')
|
|
165
|
+
|
|
166
|
+
# update params in config files
|
|
167
|
+
for root, dirs, files in os.walk(odps_oss_config.temp_dir):
|
|
168
|
+
for file in files:
|
|
169
|
+
file_path = os.path.join(root, file)
|
|
170
|
+
# drop .template
|
|
171
|
+
if file_path.endswith('.template'):
|
|
172
|
+
tmp_path = file_path[:-len('.template')]
|
|
173
|
+
os.rename(file_path, tmp_path)
|
|
174
|
+
file_path = tmp_path
|
|
175
|
+
if 'data' not in file_path:
|
|
176
|
+
logging.info('modify %s' % file_path)
|
|
177
|
+
change_files(odps_oss_config, file_path)
|
|
178
|
+
|
|
179
|
+
# put data to test bucket
|
|
180
|
+
put_data_to_bucket(odps_oss_config)
|
|
181
|
+
|
|
182
|
+
# mkdir log dir
|
|
183
|
+
if not os.path.exists(odps_oss_config.log_dir):
|
|
184
|
+
os.makedirs(odps_oss_config.log_dir)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
if __name__ == '__main__':
|
|
188
|
+
if len(sys.argv) < 5:
|
|
189
|
+
print('usage: %s ossutilconfig bucket_name rolearn odpsconfig' %
|
|
190
|
+
sys.argv[0])
|
|
191
|
+
sys.exit(1)
|
|
192
|
+
|
|
193
|
+
odps_oss_config = OdpsOSSConfig()
|
|
194
|
+
odps_oss_config.load_oss_config(sys.argv[1])
|
|
195
|
+
odps_oss_config.bucket_name = sys.argv[2]
|
|
196
|
+
odps_oss_config.arn = sys.argv[3]
|
|
197
|
+
odps_oss_config.load_odps_config(sys.argv[4])
|
|
198
|
+
prepare(odps_oss_config)
|