/usr/local/lib64/python3.6/site-packages/caffe2/python/__pycache__
NameSizeModeActions
allcompare_test.cpython-36.pyc27100644editdlrm
attention.cpython-36.pyc49380644editdlrm
benchmark_generator.cpython-36.pyc39100644editdlrm
binarysize.cpython-36.pyc48530644editdlrm
brew.cpython-36.pyc38490644editdlrm
brew_test.cpython-36.pyc104520644editdlrm
build.cpython-36.pyc3400644editdlrm
cached_reader.cpython-36.pyc29540644editdlrm
caffe_translator.cpython-36.pyc241650644editdlrm
caffe_translator_test.cpython-36.pyc29290644editdlrm
checkpoint.cpython-36.pyc279730644editdlrm
checkpoint_test.cpython-36.pyc94620644editdlrm
cnn.cpython-36.pyc84350644editdlrm
context.cpython-36.pyc40080644editdlrm
context_test.cpython-36.pyc26650644editdlrm
control.cpython-36.pyc144660644editdlrm
control_ops_grad.cpython-36.pyc163650644editdlrm
control_ops_grad_test.cpython-36.pyc15020644editdlrm
control_ops_util.cpython-36.pyc83320644editdlrm
control_test.cpython-36.pyc118700644editdlrm
convert.cpython-36.pyc1480644editdlrm
convert_test.cpython-36.pyc5680644editdlrm
convnet_benchmarks.cpython-36.pyc129450644editdlrm
convnet_benchmarks_test.cpython-36.pyc10900644editdlrm
core.cpython-36.pyc944280644editdlrm
core_gradients_test.cpython-36.pyc248250644editdlrm
core_test.cpython-36.pyc339420644editdlrm
crf.cpython-36.pyc76220644editdlrm
crf_predict.cpython-36.pyc10440644editdlrm
crf_viterbi_test.cpython-36.pyc16770644editdlrm
dataio.cpython-36.pyc239780644editdlrm
dataio_test.cpython-36.pyc132670644editdlrm
dataset.cpython-36.pyc128790644editdlrm
data_parallel_model.cpython-36.pyc514160644editdlrm
data_parallel_model_test.cpython-36.pyc389230644editdlrm
data_workers.cpython-36.pyc131420644editdlrm
data_workers_test.cpython-36.pyc45220644editdlrm
db_file_reader.cpython-36.pyc53610644editdlrm
db_test.cpython-36.pyc13280644editdlrm
device_checker.cpython-36.pyc40140644editdlrm
dyndep.cpython-36.pyc15680644editdlrm
embedding_generation_benchmark.cpython-36.pyc42030644editdlrm
experiment_util.cpython-36.pyc32330644editdlrm
extension_loader.cpython-36.pyc5430644editdlrm
fakefp16_transform_lib.cpython-36.pyc5460644editdlrm
filler_test.cpython-36.pyc9250644editdlrm
functional.cpython-36.pyc35310644editdlrm
functional_test.cpython-36.pyc41320644editdlrm
fused_8bit_rowwise_conversion_ops_test.cpython-36.pyc36310644editdlrm
gradient_checker.cpython-36.pyc106220644editdlrm
gradient_check_test.cpython-36.pyc167880644editdlrm
gru_cell.cpython-36.pyc25960644editdlrm
hip_test_util.cpython-36.pyc6690644editdlrm
hsm_util.cpython-36.pyc18230644editdlrm
hypothesis_test.cpython-36.pyc843120644editdlrm
hypothesis_test_util.cpython-36.pyc200390644editdlrm
ideep_test_util.cpython-36.pyc10810644editdlrm
layers_test.cpython-36.pyc573720644editdlrm
layer_model_helper.cpython-36.pyc216410644editdlrm
layer_model_instantiator.cpython-36.pyc36650644editdlrm
layer_parameter_sharing_test.cpython-36.pyc56260644editdlrm
layer_test_util.cpython-36.pyc52730644editdlrm
lazy.cpython-36.pyc4240644editdlrm
lazy_dyndep.cpython-36.pyc24750644editdlrm
lazy_dyndep_test.cpython-36.pyc48070644editdlrm
lengths_reducer_fused_8bit_rowwise_ops_test.cpython-36.pyc43920644editdlrm
lengths_reducer_rowwise_8bit_ops_test.cpython-36.pyc36840644editdlrm
lstm_benchmark.cpython-36.pyc72820644editdlrm
memonger.cpython-36.pyc321700644editdlrm
memonger_test.cpython-36.pyc231000644editdlrm
mkl_test_util.cpython-36.pyc11910644editdlrm
model_device_test.cpython-36.pyc33760644editdlrm
model_helper.cpython-36.pyc186180644editdlrm
model_helper_test.cpython-36.pyc19910644editdlrm
modifier_context.cpython-36.pyc26500644editdlrm
muji.cpython-36.pyc55660644editdlrm
muji_test.cpython-36.pyc35670644editdlrm
net_builder.cpython-36.pyc267860644editdlrm
net_builder_test.cpython-36.pyc92550644editdlrm
net_drawer.cpython-36.pyc100560644editdlrm
net_printer.cpython-36.pyc143670644editdlrm
net_printer_test.cpython-36.pyc33230644editdlrm
nomnigraph.cpython-36.pyc51250644editdlrm
nomnigraph_test.cpython-36.pyc145910644editdlrm
nomnigraph_transformations.cpython-36.pyc24310644editdlrm
nomnigraph_transformations_test.cpython-36.pyc40730644editdlrm
normalizer.cpython-36.pyc19410644editdlrm
normalizer_context.cpython-36.pyc15530644editdlrm
normalizer_test.cpython-36.pyc8700644editdlrm
numa_benchmark.cpython-36.pyc18860644editdlrm
numa_test.cpython-36.pyc16260644editdlrm
observer_test.cpython-36.pyc41810644editdlrm
operator_fp_exceptions_test.cpython-36.pyc13050644editdlrm
optimizer.cpython-36.pyc456060644editdlrm
optimizer_context.cpython-36.pyc20080644editdlrm
optimizer_test.cpython-36.pyc247470644editdlrm
optimizer_test_util.cpython-36.pyc68080644editdlrm
parallelize_bmuf_distributed_test.cpython-36.pyc69900644editdlrm
parallel_workers.cpython-36.pyc91480644editdlrm
parallel_workers_test.cpython-36.pyc38240644editdlrm
pipeline.cpython-36.pyc129400644editdlrm
pipeline_test.cpython-36.pyc27150644editdlrm
predictor_constants.cpython-36.pyc3040644editdlrm
python_op_test.cpython-36.pyc105020644editdlrm
queue_util.cpython-36.pyc50550644editdlrm
record_queue.cpython-36.pyc42250644editdlrm
recurrent.cpython-36.pyc98930644editdlrm
regularizer.cpython-36.pyc186040644editdlrm
regularizer_context.cpython-36.pyc15620644editdlrm
regularizer_test.cpython-36.pyc88250644editdlrm
rnn_cell.cpython-36.pyc447850644editdlrm
schema.cpython-36.pyc417630644editdlrm
schema_test.cpython-36.pyc137870644editdlrm
scope.cpython-36.pyc26000644editdlrm
scope_test.cpython-36.pyc40680644editdlrm
session.cpython-36.pyc73460644editdlrm
session_test.cpython-36.pyc23530644editdlrm
sparse_to_dense_mask_test.cpython-36.pyc52980644editdlrm
sparse_to_dense_test.cpython-36.pyc30030644editdlrm
task.cpython-36.pyc222070644editdlrm
task_test.cpython-36.pyc11780644editdlrm
test_util.cpython-36.pyc37290644editdlrm
text_file_reader.cpython-36.pyc22390644editdlrm
timeout_guard.cpython-36.pyc31060644editdlrm
toy_regression_test.cpython-36.pyc23600644editdlrm
transformations.cpython-36.pyc18330644editdlrm
transformations_test.cpython-36.pyc96080644editdlrm
tt_core.cpython-36.pyc64680644editdlrm
tt_core_test.cpython-36.pyc18240644editdlrm
utils.cpython-36.pyc122450644editdlrm
utils_test.cpython-36.pyc14160644editdlrm
visualize.cpython-36.pyc60270644editdlrm
workspace.cpython-36.pyc226900644editdlrm
workspace_test.cpython-36.pyc290550644editdlrm
_import_c_extension.cpython-36.pyc15240644editdlrm
__init__.cpython-36.pyc26070644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/caffe2/python/__pycache__/regularizer.cpython-36.pyc (18604B)
3 EgR@s,ddlmZmZddlZGdddeZGdddeZGdddeZGd d d eZ Gd d d eZ Gd ddeZ GdddeZ GdddeZ GdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdd d eZGd!d"d"eZGd#d$d$eZdS)%)coreutilsNc@seZdZdZdZdS)RegularizationByZafter_optimizerZon_lossN)__name__ __module__ __qualname__ZAFTER_OPTIMIZERZON_LOSSrrE/usr/local/lib64/python3.6/site-packages/caffe2/python/regularizer.pyr src@sBeZdZddZdddZdddZdd Zd d Zdd dZdS) RegularizercCs d|_dS)Ng& .>)kEpsilon)selfrrr __init__szRegularizer.__init__NcCsvt|tjsttjt}||jks>tdj|j ||jd|}t ||sbtdj|j |t ||||||S)Nz>Regularizer of type {} is called with invalid by={}, not in {}Z_run_z5Regularizer of type {} does not implement function {}) isinstancerZ BlobReferenceAssertionErrorrZEnumClassKeyValsrvaluesformat __class__hasattrgetattr)r netparam_init_netparamgradZbyZby_enumrun_funcrrr __call__s   zRegularizer.__call__cCsdS)Nr)r rrrrrrr _run_on_loss'szRegularizer._run_on_losscCsdS)Nr)r rrrrrrr _run_after_optimizer*sz Regularizer._run_after_optimizercCsL|j||g|jdg}|j|g|jdg}|j|g|jdgdd}|S)N param_mul param_reducedgrouped_feature_weight_vecg?)exponent)MulNextScopedBlobReduceFrontSumPow)r rrrrrrrr _feature_grouping-s zRegularizer._feature_groupingFc Cst|dk r|s|r||jn|}|dk r8|s.|r8||jn|}t|tjrV||j|jgn|g} |j| |g||ddS)N)minmax)r rr GradientSliceindicesrZ EnsureClipped) r rrrr&r' open_range left_open right_openZ input_blobsrrr _ensure_clipped=s zRegularizer._ensure_clipped)NN)N)NNNFFF) rrrr rrrr%r-rrrr r s  r cs&eZdZfddZdddZZS)L1Normcs(tt|j|dkstd||_dS)Nrz6factor ahead of regularization should be 0 or positive)superr.r r reg_lambda)r r0)rrr r [szL1Norm.__init__NcCs<|j|d}|j|g|gdd|j|g|g|jd|S)NZ_l1_regularization)p)scale)r"LpNormScaler0)r rrrr output_blobrrr raszL1Norm._run_on_loss)N)rrrr r __classcell__rr)rr r.Zs r.cs(eZdZdfdd ZdddZZS) r4?cs>tt|j|dkstd|dks.td||_||_dS)a  reg_lambda: parameter to scale regularization by p_value: determines what type of Lp norm to calculate. If p > 0, we will calculate Lp norm with the formula: pow( sum_i { pow(theda_i, p) } , 1/p) rz7factor ahead of regularization should be greater than 0z'p_value factor should be greater than 0N)r/r4r rp_valuer0)r r0r9)rrr r hs zLpNorm.__init__Nc Cs|j|d}|j||}|j|g|jdg|jd}|j|g|jdg}|j|g|jdgd|jd} |j| g|g|jd|S)N_dense_feature_regularization lp_vec_raised)r lp_vec_summedZlp_vecr1)r3)r"r%r$r9r#r5r0) r rrrrr6rr;r<Zlp_normrrr rws    zLpNorm._run_on_loss)r8)N)rrrr rr7rr)rr r4gsr4cs(eZdZdfdd Zd ddZZS) L0ApproxNorm{Gz?rcsXtt|j|dkstd|dks.td|dks>td||_||_t||_dS)a9 reg_lambda: parameter to scale regularization by alpha: hyper parameter to tune that is only used in the calculation of approximate L0 norm budget: desired number of features. If the number of features is greater than the budget amount, then the least important features will be penalized. If there are fewer features than the desired budget, no penalization will be applied. Optional parameter, if 0, then no budget is used rz7factor ahead of regularization should be greater than 0z4alpha factor must be a positive value greater than 0z0budget factor must be greater than or equal to 0N)r/r=r rr0alphafloatbudget)r r0r?rA)rrr r s zL0ApproxNorm.__init__NcCs|j|d}|j||}|j|g|jdg}|j|g|jdg|jd}|j|g|jdg} |j| g|jdgd|jd} |jr|jgd dg|jd } |j | | g|jd g} |j | g|jd g} |j| g|g|j dn|j| g|g|j d|S) Nr:l0_absl0_min)r' l0_summedl0_normr1)r3rA)shapevalueZ l0_budgetrelu_l0_sub_budget) r"r%AbsClipr?r#r5rA ConstantFillSubZRelur0)r rrrrr6rrBrCrDrEZ budget_blobZ l0_sub_budgetrHrrr rs  zL0ApproxNorm._run_on_loss)r>r)N)rrrr rr7rr)rr r=sr=cs*eZdZdZfddZdddZZS) L1NormTrimmedzV The Trimmed Lasso: Sparsity and Robustness. https://arxiv.org/abs/1708.04527 csPtt|j|dkstdt|ts0td|dks@td||_||_dS)Nrz6factor ahead of regularization should be 0 or positivez6k should be an interger as expected #. after selectionr1zk should be larger than 1)r/rMr rrintr0k)r r0rO)rrr r s zL1NormTrimmed.__init__Nc Cs|j|d}|j|g|jdg}|j|g|jdgdd}|j|g|jd|jd|jdg|jd \}} } |j|g|jd gdd} |j|| g|g|j|g|g|jd |S) NZ_l1_trimmed_regularizationabssum_absF)averagetopkidflat_id)rOtopk_sum)r3)r"rI SumElementsTopKrOrLr5r0) r rrrrr6rPrQrS_rVrrr rs2zL1NormTrimmed._run_on_loss)N)rrr__doc__r rr7rr)rr rMs rMcs&eZdZfddZdddZZS)L2Normcs(tt|j|dkstd||_dS)Nrz6factor ahead of regularization should be 0 or positive)r/r[r rr0)r r0)rrr r szL2Norm.__init__NcCs<|j|d}|j|g|gdd|j|g|g|jd|S)NZ_l2_regularization)r2)r3)r"r4r5r0)r rrrrr6rrr rszL2Norm._run_on_loss)N)rrrr rr7rr)rr r[s r[cs&eZdZfddZdddZZS) ElasticNetcstt|j||_||_dS)N)r/r]r l1l2)r r^r_)rrr r szElasticNet.__init__NcCs|j|d}|j|d}|j|d}|j|g|gdd|j|g|gdd|j|g|g|jd|j|g|g|jd|j||g|g|S)NZ_elastic_net_regularization_l2_blob_l1_blobr\)r2r1)r3)r"r4r5r_r^Add)r rrrrr6l2_blobl1_blobrrr rszElasticNet._run_on_loss)N)rrrr rr7rr)rr r]s r]cs&eZdZfddZdddZZS)ElasticNetL1NormTrimmedcs$tt|j||_||_||_dS)N)r/rer r^r_rO)r r^r_rO)rrr r sz ElasticNetL1NormTrimmed.__init__Nc Cs|j|d}|j|d}|j|g|gdd|j|g|g|jd|j|d}|j|g|jdg}|j|g|jdgd d } |j|g|jd |jd |jd g|jd\} } } |j| g|jdgd d } |j| | g|g|j|g|g|j d|j ||g|g|S)NZ&_elastic_net_l1_trimmed_regularizationr`r\)r2)r3rarPrQF)rRrSrTrU)rOrV) r"r4r5r_rIrWrXrOrLr^rb) r rrrrr6rcrdrPrQrSrYrVrrr r s2z$ElasticNetL1NormTrimmed._run_on_loss)N)rrrr rr7rr)rr res recs&eZdZdfdd ZddZZS)MaxNorm?Ncstt|j||_||_dS)N)r/rfr normdtype)r rhri)rrr r szMaxNorm.__init__cCsv|jdkstdt|tjrj|jrL|jdkrL|j||jg|gd|jdqr|j||jg|gd|jdnt ddS)Nrznorm should be bigger than 0.Zfp16T) use_max_normrhz-MaxNorm is not supported for dense parameters) rhrrrr(riZFloat16SparseNormalizer)SparseNormalizeNotImplementedError)r rrrrrrr r!s   zMaxNorm._run_after_optimizer)rgN)rrrr rr7rr)rr rfsrfcs&eZdZdfdd ZddZZS) ConstantNorm?cstt|j||_dS)N)r/rmr rh)r rh)rrr r 7szConstantNorm.__init__cCsH|jdkstdt|tjr<|j||jg|gd|jdntddS)Nrznorm should be bigger than 0.F)rjrhz2ConstantNorm is not supported for dense parameters)rhrrrr(rkr)rl)r rrrrrrr r;s  z!ConstantNorm._run_after_optimizer)rn)rrrr rr7rr)rr rm6srmcs$eZdZfddZddZZS) SparseLpNormcs>tt|j|dkstd|dks.td||_||_dS)N?@zBSparse Lp regularization only implemented for p = 1.0 and p = 2.0.rz8factor ahead of regularization should be greater than 0.)rprq)r/ror rr2r0)r r2r0)rrr r Ks zSparseLpNorm.__init__cCs8t|tjr,|j||jg|g|j|jdntddS)N)r2r0z2SparseLpNorm is not supported for dense parameters)rrr(ZSparseLpRegularizerr)r2r0rl)r rrrrrrr rRs  z!SparseLpNorm._run_after_optimizer)rrrr rr7rr)rr roJs rocseZdZfddZZS) SparseL1Normcstt|jd|ddS)Ng?)r2r0)r/rrr )r r0)rrr r _szSparseL1Norm.__init__)rrrr r7rr)rr rr^srrcseZdZfddZZS) SparseL2Normcstt|jd|ddS)Ng@)r2r0)r/rsr )r r0)rrr r dszSparseL2Norm.__init__)rrrr r7rr)rr rscsrscs4eZdZdZd fdd Zd ddZdd ZZS) LogBarrierzr Wright, S., & Nocedal, J. (1999). Numerical optimization. Springer Science, 35(67-68), 7. Chapter 19 invNcs>tt|j|dkstd||_||_|p6ddd|_dS)z discount is a positive weight that is decreasing, and here it is implemented similar to the learning rate. It is specified by a learning rate policy and corresponding options rz6factor ahead of regularization should be 0 or positiveg?)gammapowerN)r/rtr rr0discount_policydiscount_options)r r0rxry)rrr r ns zLogBarrier.__init__c Cstj||}|j|d}|j|g|gf|j |jd|j|j|d}|j|g|g|jd|j|d}|j |g|g|j|d} |j |g| g|j|d} |j | |g| gdd | S) NZ_log_barrier_discount)Zbase_lrpolicyZ_non_neg)r&_logZ_log_sumZ _log_barrierr1) broadcast) rZBuildUniqueMutexIterr"Z LearningRater0rxryrJr LogrWr!) r rrrr iterationZdiscountZ param_non_negZ param_logZ param_log_sumr6rrr rzs"  zLogBarrier._run_on_losscCs|j|||ddddS)NrT)r&r*)r-)r rrrrrrr rszLogBarrier._run_after_optimizer)ruN)N)rrrrZr rrr7rr)rr rths rtcs*eZdZdZdfdd ZddZZS) BoundedGradientProjectionzr Wright, S., & Nocedal, J. (1999). Numerical optimization. Springer Science, 35(67-68), 7. Chapter 16 NFcstt|j|dk rt|nd}|dk r2t|nd}|dk rFt|n|j}|dksdtdj|d|dks|dks||r~|nd||r|ndkstdj|||rdnd|rdnd |d ||_||_||_||_ ||_ dS) Nrz2Bounded Gradient Projection with invalid eps={eps})epsgzLBounded Gradient Projection with invalid {lp}ub={ub}, lb={lb}{rp}, eps={eps}([)])lbubZlprpr) r/rr r@r rrr+r,rr)r rrr+r,epsilon)rrr r s*    z"BoundedGradientProjection.__init__c Cs$|j||||j|j|j|jddS)N)r&r'r+r,)r-rrr+r,)r rrrrrrr rsz.BoundedGradientProjection._run_after_optimizer)NNFFN)rrrrZr rr7rr)rr rs rcs,eZdZdZdfdd Zd ddZZS) GroupL1Norma Scardapane, Simone, et al. "Group sparse regularization for deep neural networks." Neurocomputing 241 (2017): 81-89. This regularizer computes l1 norm of a weight matrix based on groups. There are essentially three stages in the computation: 1. Compute the l2 norm on all the members of each group 2. Scale each l2 norm by the size of each group 3. Compute the l1 norm of the scaled l2 norms rcsFtt|j|dkstdt|ts0td||_||_||_dS)a Args: reg_lambda: The weight of the regularization term. groups: A list of integers describing the size of each group. The length of the list is the number of groups. Optional Args: stabilizing_val: The computation of GroupL1Norm involves the Sqrt operator. When values are small, its gradient can be numerically unstable and causing gradient explosion. Adding this term to stabilize gradient calculation. Recommended value of this term is 1e-8, but it depends on the specific scenarios. If the implementation of the gradient operator of Sqrt has taken into stability into consideration, this term won't be necessary. rz-regularization weight should be 0 or positivezgroups needs to be a listN) r/rr rrlistr0groupsstabilizing_val)r r0rr)rrr r s zGroupL1Norm.__init__Nc Cs|j|}|j|dgdd}|j||jgdt|jg|jdg}|jrl|j||jgd|jdg|gdd|j |}|j ||j gt|jgt j |j|jdgdg} |j| dgdd } | S) a Args: param: The input blob to regularize. It should be a weight matrix blob with shape (output_dim, input_dim). input_dim should be equal to the sum of self.groups. Returns: group_l1_norm: The output blob after applying regularization. These are the steps of computation: 1. square all elements 2. sum by row 3. lengthssum by group 4. square_root all elements 5. normalize each group based on group size 6. compute l1 norm of each group 7. scale the result with the regularization lambda r)ZaxesZkeepdimsr1)rFr)rG)r|Znormalized_l2_norm_scaledZ group_l1_nrom)r2)ZSqrZ ReduceSumZ LengthsSumZGivenTensorIntFilllenrrrbrKZSqrtr!ZGivenTensorFillnpsqrtr0r4) r rrrrZsquaredZ reduced_sumZ lengths_sumrZ l2_scaledZ group_l1_normrrr rs*   zGroupL1Norm._run_on_loss)r)N)rrrrZr rr7rr)rr rs r)Z caffe2.pythonrrZnumpyrobjectrr r.r4r=rMr[r]rerfrmrorrrsrtrrrrrr s$L ,7.3