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,311 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Module implementing queues
|
|
3
|
+
#
|
|
4
|
+
# multiprocessing/queues.py
|
|
5
|
+
#
|
|
6
|
+
# Copyright (c) 2006-2008, R Oudkerk
|
|
7
|
+
# Licensed to PSF under a Contributor Agreement.
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
import collections
|
|
11
|
+
import errno
|
|
12
|
+
import logging
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
import threading
|
|
16
|
+
import time
|
|
17
|
+
import weakref
|
|
18
|
+
from multiprocessing import connection
|
|
19
|
+
from multiprocessing.util import Finalize
|
|
20
|
+
from multiprocessing.util import is_exiting
|
|
21
|
+
from multiprocessing.util import register_after_fork
|
|
22
|
+
from queue import Empty
|
|
23
|
+
from queue import Full
|
|
24
|
+
|
|
25
|
+
import six
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
from multiprocessing import context
|
|
29
|
+
except ImportError:
|
|
30
|
+
context = None
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
if context is not None:
|
|
34
|
+
_ForkingPickler = context.reduction.ForkingPickler
|
|
35
|
+
else:
|
|
36
|
+
_ForkingPickler = None
|
|
37
|
+
|
|
38
|
+
#
|
|
39
|
+
# Queue type using a pipe, buffer and thread
|
|
40
|
+
#
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class Queue(object):
|
|
44
|
+
|
|
45
|
+
_sentinel = object()
|
|
46
|
+
|
|
47
|
+
def __init__(self, ctx, maxsize=0, name=''):
|
|
48
|
+
assert not six.PY2, 'python2 is not supported'
|
|
49
|
+
if maxsize <= 0:
|
|
50
|
+
# Can raise ImportError (see issues #3770 and #23400)
|
|
51
|
+
from multiprocessing.synchronize import SEM_VALUE_MAX as maxsize
|
|
52
|
+
self._maxsize = maxsize
|
|
53
|
+
self._reader, self._writer = connection.Pipe(duplex=False)
|
|
54
|
+
self._rlock = ctx.Lock()
|
|
55
|
+
self._opid = os.getpid()
|
|
56
|
+
if sys.platform == 'win32':
|
|
57
|
+
self._wlock = None
|
|
58
|
+
else:
|
|
59
|
+
self._wlock = ctx.Lock()
|
|
60
|
+
self._sem = ctx.BoundedSemaphore(maxsize)
|
|
61
|
+
# For use by concurrent.futures
|
|
62
|
+
self._ignore_epipe = False
|
|
63
|
+
self._reset()
|
|
64
|
+
self._name = name
|
|
65
|
+
self._run = True
|
|
66
|
+
|
|
67
|
+
if sys.platform != 'win32':
|
|
68
|
+
register_after_fork(self, Queue._after_fork)
|
|
69
|
+
|
|
70
|
+
def __getstate__(self):
|
|
71
|
+
context.assert_spawning(self)
|
|
72
|
+
return (self._ignore_epipe, self._maxsize, self._reader, self._writer,
|
|
73
|
+
self._rlock, self._wlock, self._sem, self._opid, self._name,
|
|
74
|
+
self._run)
|
|
75
|
+
|
|
76
|
+
def __setstate__(self, state):
|
|
77
|
+
(self._ignore_epipe, self._maxsize, self._reader, self._writer, self._rlock,
|
|
78
|
+
self._wlock, self._sem, self._opid, self._name, self._run) = state
|
|
79
|
+
self._reset()
|
|
80
|
+
|
|
81
|
+
def _after_fork(self):
|
|
82
|
+
logging.debug('Queue._after_fork()')
|
|
83
|
+
self._reset(after_fork=True)
|
|
84
|
+
|
|
85
|
+
def _reset(self, after_fork=False):
|
|
86
|
+
if after_fork:
|
|
87
|
+
self._notempty._at_fork_reinit()
|
|
88
|
+
else:
|
|
89
|
+
self._notempty = threading.Condition(threading.Lock())
|
|
90
|
+
self._buffer = collections.deque()
|
|
91
|
+
self._thread = None
|
|
92
|
+
self._jointhread = None
|
|
93
|
+
self._joincancelled = False
|
|
94
|
+
self._closed = False
|
|
95
|
+
self._close = None
|
|
96
|
+
self._send_bytes = self._writer.send_bytes
|
|
97
|
+
self._recv_bytes = self._reader.recv_bytes
|
|
98
|
+
self._poll = self._reader.poll
|
|
99
|
+
|
|
100
|
+
def put(self, obj, block=True, timeout=None):
|
|
101
|
+
if self._closed:
|
|
102
|
+
raise ValueError('Queue %s is closed' % self._name)
|
|
103
|
+
if not self._sem.acquire(block, timeout):
|
|
104
|
+
raise Full
|
|
105
|
+
|
|
106
|
+
with self._notempty:
|
|
107
|
+
if self._thread is None:
|
|
108
|
+
self._start_thread()
|
|
109
|
+
self._buffer.append(obj)
|
|
110
|
+
self._notempty.notify()
|
|
111
|
+
|
|
112
|
+
def get(self, block=True, timeout=None):
|
|
113
|
+
if self._closed:
|
|
114
|
+
raise ValueError('Queue %s is closed' % self._name)
|
|
115
|
+
if block and timeout is None:
|
|
116
|
+
with self._rlock:
|
|
117
|
+
res = self._recv_bytes()
|
|
118
|
+
self._sem.release()
|
|
119
|
+
else:
|
|
120
|
+
if block:
|
|
121
|
+
deadline = time.monotonic() + timeout
|
|
122
|
+
if not self._rlock.acquire(block, timeout):
|
|
123
|
+
raise Empty
|
|
124
|
+
try:
|
|
125
|
+
if block:
|
|
126
|
+
timeout = deadline - time.monotonic()
|
|
127
|
+
if not self._poll(timeout):
|
|
128
|
+
raise Empty
|
|
129
|
+
elif not self._poll():
|
|
130
|
+
raise Empty
|
|
131
|
+
res = self._recv_bytes()
|
|
132
|
+
self._sem.release()
|
|
133
|
+
finally:
|
|
134
|
+
self._rlock.release()
|
|
135
|
+
# unserialize the data after having released the lock
|
|
136
|
+
return _ForkingPickler.loads(res)
|
|
137
|
+
|
|
138
|
+
def qsize(self):
|
|
139
|
+
# Raises NotImplementedError on Mac OSX because of broken sem_getvalue()
|
|
140
|
+
return self._maxsize - self._sem._semlock._get_value()
|
|
141
|
+
|
|
142
|
+
def empty(self):
|
|
143
|
+
return not self._poll()
|
|
144
|
+
|
|
145
|
+
def full(self):
|
|
146
|
+
return self._sem._semlock._is_zero()
|
|
147
|
+
|
|
148
|
+
def get_nowait(self):
|
|
149
|
+
return self.get(False)
|
|
150
|
+
|
|
151
|
+
def put_nowait(self, obj):
|
|
152
|
+
return self.put(obj, False)
|
|
153
|
+
|
|
154
|
+
def close(self, wait_send_finish=True):
|
|
155
|
+
self._closed = True
|
|
156
|
+
close = self._close
|
|
157
|
+
if not wait_send_finish and self._thread is not None and self._thread.is_alive(
|
|
158
|
+
):
|
|
159
|
+
try:
|
|
160
|
+
if self._reader is not None:
|
|
161
|
+
self._reader.close()
|
|
162
|
+
except Exception:
|
|
163
|
+
pass
|
|
164
|
+
self._run = False
|
|
165
|
+
# clear queue
|
|
166
|
+
# with self._rlock:
|
|
167
|
+
# while self._thread.is_alive() and self._poll(1):
|
|
168
|
+
# res = self._recv_bytes()
|
|
169
|
+
# logging.info('Queue[name=' + self._name + '] clear one elem')
|
|
170
|
+
# logging.info('Queue[name=' + self._name + '] clear queue done')
|
|
171
|
+
if close:
|
|
172
|
+
self._close = None
|
|
173
|
+
close()
|
|
174
|
+
|
|
175
|
+
def join_thread(self):
|
|
176
|
+
logging.debug('Queue.join_thread()')
|
|
177
|
+
assert self._closed, 'Queue {0!r} not closed'.format(self)
|
|
178
|
+
if self._jointhread:
|
|
179
|
+
self._jointhread()
|
|
180
|
+
|
|
181
|
+
def cancel_join_thread(self):
|
|
182
|
+
logging.debug('Queue.cancel_join_thread()')
|
|
183
|
+
self._joincancelled = True
|
|
184
|
+
try:
|
|
185
|
+
self._jointhread.cancel()
|
|
186
|
+
except AttributeError:
|
|
187
|
+
pass
|
|
188
|
+
|
|
189
|
+
def _start_thread(self):
|
|
190
|
+
logging.debug('Queue._start_thread()')
|
|
191
|
+
|
|
192
|
+
# Start thread which transfers data from buffer to pipe
|
|
193
|
+
self._buffer.clear()
|
|
194
|
+
self._thread = threading.Thread(
|
|
195
|
+
target=self._feed,
|
|
196
|
+
args=(self._buffer, self._notempty, self._send_bytes, self._wlock,
|
|
197
|
+
self._reader.close, self._writer.close, self._ignore_epipe,
|
|
198
|
+
self._on_queue_feeder_error, self._sem),
|
|
199
|
+
name='QueueFeederThread')
|
|
200
|
+
self._thread.daemon = True
|
|
201
|
+
|
|
202
|
+
logging.debug('doing self._thread.start()')
|
|
203
|
+
self._thread.start()
|
|
204
|
+
logging.debug('... done self._thread.start()')
|
|
205
|
+
|
|
206
|
+
if not self._joincancelled:
|
|
207
|
+
self._jointhread = Finalize(
|
|
208
|
+
self._thread,
|
|
209
|
+
Queue._finalize_join, [weakref.ref(self._thread)],
|
|
210
|
+
exitpriority=-5)
|
|
211
|
+
|
|
212
|
+
# Send sentinel to the thread queue object when garbage collected
|
|
213
|
+
self._close = Finalize(
|
|
214
|
+
self,
|
|
215
|
+
Queue._finalize_close, [self._buffer, self._notempty],
|
|
216
|
+
exitpriority=10)
|
|
217
|
+
|
|
218
|
+
@staticmethod
|
|
219
|
+
def _finalize_join(twr):
|
|
220
|
+
logging.debug('joining queue thread')
|
|
221
|
+
thread = twr()
|
|
222
|
+
if thread is not None:
|
|
223
|
+
thread.join()
|
|
224
|
+
logging.debug('... queue thread joined')
|
|
225
|
+
else:
|
|
226
|
+
logging.debug('... queue thread already dead')
|
|
227
|
+
|
|
228
|
+
@staticmethod
|
|
229
|
+
def _finalize_close(buffer, notempty):
|
|
230
|
+
logging.debug('telling queue thread to quit')
|
|
231
|
+
with notempty:
|
|
232
|
+
buffer.append(Queue._sentinel)
|
|
233
|
+
notempty.notify()
|
|
234
|
+
|
|
235
|
+
def _feed(self, buffer, notempty, send_bytes, writelock, reader_close,
|
|
236
|
+
writer_close, ignore_epipe, onerror, queue_sem):
|
|
237
|
+
logging.debug('starting thread to feed data to pipe')
|
|
238
|
+
nacquire = notempty.acquire
|
|
239
|
+
nrelease = notempty.release
|
|
240
|
+
nwait = notempty.wait
|
|
241
|
+
bpopleft = buffer.popleft
|
|
242
|
+
sentinel = Queue._sentinel
|
|
243
|
+
if sys.platform != 'win32':
|
|
244
|
+
wacquire = writelock.acquire
|
|
245
|
+
wrelease = writelock.release
|
|
246
|
+
else:
|
|
247
|
+
wacquire = None
|
|
248
|
+
|
|
249
|
+
pid = os.getpid()
|
|
250
|
+
name = self._name
|
|
251
|
+
while self._run:
|
|
252
|
+
try:
|
|
253
|
+
nacquire()
|
|
254
|
+
try:
|
|
255
|
+
if not buffer:
|
|
256
|
+
nwait()
|
|
257
|
+
finally:
|
|
258
|
+
nrelease()
|
|
259
|
+
try:
|
|
260
|
+
while self._run:
|
|
261
|
+
obj = bpopleft()
|
|
262
|
+
if obj is sentinel:
|
|
263
|
+
# logging.info('Queue[' + self._name + '] feeder thread got sentinel -- exiting: ' + str(self._run))
|
|
264
|
+
reader_close()
|
|
265
|
+
writer_close()
|
|
266
|
+
return
|
|
267
|
+
|
|
268
|
+
# serialize the data before acquiring the lock
|
|
269
|
+
obj = _ForkingPickler.dumps(obj)
|
|
270
|
+
if wacquire is None:
|
|
271
|
+
send_bytes(obj)
|
|
272
|
+
else:
|
|
273
|
+
wacquire()
|
|
274
|
+
try:
|
|
275
|
+
send_bytes(obj)
|
|
276
|
+
finally:
|
|
277
|
+
wrelease()
|
|
278
|
+
except IndexError:
|
|
279
|
+
pass
|
|
280
|
+
except Exception as e:
|
|
281
|
+
if ignore_epipe and getattr(e, 'errno', 0) == errno.EPIPE:
|
|
282
|
+
logging.warning('Queue[' + name + '] exception: pid=' + str(pid) +
|
|
283
|
+
' run=' + str(self._run) + ' e=' + str(e))
|
|
284
|
+
return
|
|
285
|
+
# Since this runs in a daemon thread the resources it uses
|
|
286
|
+
# may be become unusable while the process is cleaning up.
|
|
287
|
+
# We ignore errors which happen after the process has
|
|
288
|
+
# started to cleanup.
|
|
289
|
+
if is_exiting():
|
|
290
|
+
logging.warning('Queue[' + name + '] thread error in exiting: pid=' +
|
|
291
|
+
str(pid) + ' run=' + str(self._run) + ' e=' + str(e))
|
|
292
|
+
return
|
|
293
|
+
else:
|
|
294
|
+
# Since the object has not been sent in the queue, we need
|
|
295
|
+
# to decrease the size of the queue. The error acts as
|
|
296
|
+
# if the object had been silently removed from the queue
|
|
297
|
+
# and this step is necessary to have a properly working
|
|
298
|
+
# queue.
|
|
299
|
+
queue_sem.release()
|
|
300
|
+
onerror(e, obj)
|
|
301
|
+
# logging.info('Queue[' + name + '] send thread finish: pid=' + str(pid)
|
|
302
|
+
# + ' run=' + str(self._run))
|
|
303
|
+
|
|
304
|
+
@staticmethod
|
|
305
|
+
def _on_queue_feeder_error(e, obj):
|
|
306
|
+
"""Private API hook called when feeding data in the background thread raises an exception.
|
|
307
|
+
|
|
308
|
+
For overriding by concurrent.futures.
|
|
309
|
+
"""
|
|
310
|
+
import traceback
|
|
311
|
+
traceback.print_exc()
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# -*- encoding:utf-8 -*-
|
|
2
|
+
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
# from tf.contrib
|
|
17
|
+
"""Regularizers for use with layers."""
|
|
18
|
+
|
|
19
|
+
from __future__ import absolute_import
|
|
20
|
+
from __future__ import division
|
|
21
|
+
from __future__ import print_function
|
|
22
|
+
|
|
23
|
+
import numbers
|
|
24
|
+
|
|
25
|
+
from tensorflow.python.framework import constant_op
|
|
26
|
+
from tensorflow.python.framework import ops
|
|
27
|
+
from tensorflow.python.ops import math_ops
|
|
28
|
+
from tensorflow.python.ops import nn
|
|
29
|
+
from tensorflow.python.ops import standard_ops
|
|
30
|
+
from tensorflow.python.platform import tf_logging as logging
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
'l1_regularizer', 'l2_regularizer', 'l1_l2_regularizer', 'sum_regularizer',
|
|
34
|
+
'apply_regularization'
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def l1_regularizer(scale, scope=None):
|
|
39
|
+
"""Returns a function that can be used to apply L1 regularization to weights.
|
|
40
|
+
|
|
41
|
+
L1 regularization encourages sparsity.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
scale: A scalar multiplier `Tensor`. 0.0 disables the regularizer.
|
|
45
|
+
scope: An optional scope name.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
A function with signature `l1(weights)` that apply L1 regularization.
|
|
49
|
+
|
|
50
|
+
Raises:
|
|
51
|
+
ValueError: If scale is negative or if scale is not a float.
|
|
52
|
+
"""
|
|
53
|
+
if isinstance(scale, numbers.Integral):
|
|
54
|
+
raise ValueError('scale cannot be an integer: %s' % scale)
|
|
55
|
+
if isinstance(scale, numbers.Real):
|
|
56
|
+
if scale < 0.:
|
|
57
|
+
raise ValueError('Setting a scale less than 0 on a regularizer: %g' %
|
|
58
|
+
scale)
|
|
59
|
+
if scale == 0.:
|
|
60
|
+
logging.info('Scale of 0 disables regularizer.')
|
|
61
|
+
return lambda _: None
|
|
62
|
+
|
|
63
|
+
def l1(weights, name=None):
|
|
64
|
+
"""Applies L1 regularization to weights."""
|
|
65
|
+
with ops.name_scope(scope, 'l1_regularizer', [weights]) as name:
|
|
66
|
+
my_scale = ops.convert_to_tensor(
|
|
67
|
+
scale, dtype=weights.dtype.base_dtype, name='scale')
|
|
68
|
+
return standard_ops.multiply(
|
|
69
|
+
my_scale,
|
|
70
|
+
standard_ops.reduce_sum(standard_ops.abs(weights)),
|
|
71
|
+
name=name)
|
|
72
|
+
|
|
73
|
+
return l1
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def l2_regularizer(scale, scope=None):
|
|
77
|
+
"""Returns a function that can be used to apply L2 regularization to weights.
|
|
78
|
+
|
|
79
|
+
Small values of L2 can help prevent overfitting the training data.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
scale: A scalar multiplier `Tensor`. 0.0 disables the regularizer.
|
|
83
|
+
scope: An optional scope name.
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
A function with signature `l2(weights)` that applies L2 regularization.
|
|
87
|
+
|
|
88
|
+
Raises:
|
|
89
|
+
ValueError: If scale is negative or if scale is not a float.
|
|
90
|
+
"""
|
|
91
|
+
if isinstance(scale, numbers.Integral):
|
|
92
|
+
raise ValueError('scale cannot be an integer: %s' % (scale,))
|
|
93
|
+
if isinstance(scale, numbers.Real):
|
|
94
|
+
if scale < 0.:
|
|
95
|
+
raise ValueError('Setting a scale less than 0 on a regularizer: %g.' %
|
|
96
|
+
scale)
|
|
97
|
+
if scale == 0.:
|
|
98
|
+
logging.info('Scale of 0 disables regularizer.')
|
|
99
|
+
return lambda _: None
|
|
100
|
+
|
|
101
|
+
def l2(weights):
|
|
102
|
+
"""Applies l2 regularization to weights."""
|
|
103
|
+
with ops.name_scope(scope, 'l2_regularizer', [weights]) as name:
|
|
104
|
+
my_scale = ops.convert_to_tensor(
|
|
105
|
+
scale, dtype=weights.dtype.base_dtype, name='scale')
|
|
106
|
+
return standard_ops.multiply(my_scale, nn.l2_loss(weights), name=name)
|
|
107
|
+
|
|
108
|
+
return l2
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def l1_l2_regularizer(scale_l1=1.0, scale_l2=1.0, scope=None):
|
|
112
|
+
"""Returns a function that can be used to apply L1 L2 regularizations.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
scale_l1: A scalar multiplier `Tensor` for L1 regularization.
|
|
116
|
+
scale_l2: A scalar multiplier `Tensor` for L2 regularization.
|
|
117
|
+
scope: An optional scope name.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
A function with signature `l1_l2(weights)` that applies a weighted sum of
|
|
121
|
+
L1 L2 regularization.
|
|
122
|
+
|
|
123
|
+
Raises:
|
|
124
|
+
ValueError: If scale is negative or if scale is not a float.
|
|
125
|
+
"""
|
|
126
|
+
if isinstance(scale_l1, numbers.Integral):
|
|
127
|
+
raise ValueError('scale_l1 cannot be an integer: %s' % (scale_l1,))
|
|
128
|
+
if isinstance(scale_l2, numbers.Integral):
|
|
129
|
+
raise ValueError('scale_l2 cannot be an integer: %s' % (scale_l2,))
|
|
130
|
+
scope = scope or 'l1_l2_regularizer'
|
|
131
|
+
if scale_l1 == 0.:
|
|
132
|
+
return l2_regularizer(scale_l2, scope)
|
|
133
|
+
if scale_l2 == 0.:
|
|
134
|
+
return l1_regularizer(scale_l1, scope)
|
|
135
|
+
return sum_regularizer([l1_regularizer(scale_l1),
|
|
136
|
+
l2_regularizer(scale_l2)],
|
|
137
|
+
scope=scope)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def sum_regularizer(regularizer_list, scope=None):
|
|
141
|
+
"""Returns a function that applies the sum of multiple regularizers.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
regularizer_list: A list of regularizers to apply.
|
|
145
|
+
scope: An optional scope name
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
A function with signature `sum_reg(weights)` that applies the
|
|
149
|
+
sum of all the input regularizers.
|
|
150
|
+
"""
|
|
151
|
+
regularizer_list = [reg for reg in regularizer_list if reg is not None]
|
|
152
|
+
if not regularizer_list:
|
|
153
|
+
return None
|
|
154
|
+
|
|
155
|
+
def sum_reg(weights):
|
|
156
|
+
"""Applies the sum of all the input regularizers."""
|
|
157
|
+
with ops.name_scope(scope, 'sum_regularizer', [weights]) as name:
|
|
158
|
+
regularizer_tensors = []
|
|
159
|
+
for reg in regularizer_list:
|
|
160
|
+
tensor = reg(weights)
|
|
161
|
+
if tensor is not None:
|
|
162
|
+
regularizer_tensors.append(tensor)
|
|
163
|
+
return math_ops.add_n(
|
|
164
|
+
regularizer_tensors, name=name) if regularizer_tensors else None
|
|
165
|
+
|
|
166
|
+
return sum_reg
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def apply_regularization(regularizer, weights_list=None):
|
|
170
|
+
"""Returns the summed penalty by applying `regularizer` to the `weights_list`.
|
|
171
|
+
|
|
172
|
+
Adding a regularization penalty over the layer weights and embedding weights
|
|
173
|
+
can help prevent overfitting the training data. Regularization over layer
|
|
174
|
+
biases is less common/useful, but assuming proper data preprocessing/mean
|
|
175
|
+
subtraction, it usually shouldn't hurt much either.
|
|
176
|
+
|
|
177
|
+
Args:
|
|
178
|
+
regularizer: A function that takes a single `Tensor` argument and returns
|
|
179
|
+
a scalar `Tensor` output.
|
|
180
|
+
weights_list: List of weights `Tensors` or `Variables` to apply
|
|
181
|
+
`regularizer` over. Defaults to the `GraphKeys.WEIGHTS` collection if
|
|
182
|
+
`None`.
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
A scalar representing the overall regularization penalty.
|
|
186
|
+
|
|
187
|
+
Raises:
|
|
188
|
+
ValueError: If `regularizer` does not return a scalar output, or if we find
|
|
189
|
+
no weights.
|
|
190
|
+
"""
|
|
191
|
+
if not weights_list:
|
|
192
|
+
weights_list = ops.get_collection(ops.GraphKeys.WEIGHTS)
|
|
193
|
+
if not weights_list:
|
|
194
|
+
raise ValueError('No weights to regularize.')
|
|
195
|
+
with ops.name_scope(
|
|
196
|
+
'get_regularization_penalty', values=weights_list) as scope:
|
|
197
|
+
penalties = [regularizer(w) for w in weights_list]
|
|
198
|
+
penalties = [
|
|
199
|
+
p if p is not None else constant_op.constant(0.0) for p in penalties
|
|
200
|
+
]
|
|
201
|
+
for p in penalties:
|
|
202
|
+
if p.get_shape().ndims != 0:
|
|
203
|
+
raise ValueError('regularizer must return a scalar Tensor instead of a '
|
|
204
|
+
'Tensor with rank %d.' % p.get_shape().ndims)
|
|
205
|
+
|
|
206
|
+
summed_penalty = math_ops.add_n(penalties, name=scope)
|
|
207
|
+
ops.add_to_collection(ops.GraphKeys.REGULARIZATION_LOSSES, summed_penalty)
|
|
208
|
+
return summed_penalty
|