fmot 3.16.0__tar.gz
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.
- fmot-3.16.0/LICENSE +1 -0
- fmot-3.16.0/MANIFEST.in +12 -0
- fmot-3.16.0/NAME +1 -0
- fmot-3.16.0/PKG-INFO +62 -0
- fmot-3.16.0/README.md +7 -0
- fmot-3.16.0/fmot/ENV_REQUIREMENTS.sh +38 -0
- fmot-3.16.0/fmot/ONNX2FQIR_REQUIREMENTS +4 -0
- fmot-3.16.0/fmot/PY_REQUIREMENTS +15 -0
- fmot-3.16.0/fmot/TF_REQUIREMENTS +2 -0
- fmot-3.16.0/fmot/VERSION +1 -0
- fmot-3.16.0/fmot/__init__.py +28 -0
- fmot-3.16.0/fmot/_open_docs.py +17 -0
- fmot-3.16.0/fmot/_supported_ops.py +93 -0
- fmot-3.16.0/fmot/beta/__init__.py +3 -0
- fmot-3.16.0/fmot/beta/_quant_viz_example.py +31 -0
- fmot-3.16.0/fmot/beta/amp.py +87 -0
- fmot-3.16.0/fmot/beta/auto_multiprecision.py +367 -0
- fmot-3.16.0/fmot/beta/heirarchical_labeling.py +60 -0
- fmot-3.16.0/fmot/beta/quant_error_visualizer.py +350 -0
- fmot-3.16.0/fmot/beta/quantize_part.py +42 -0
- fmot-3.16.0/fmot/beta/signal24/__init__.py +3 -0
- fmot-3.16.0/fmot/beta/signal24/examples.py +218 -0
- fmot-3.16.0/fmot/beta/signal24/fft_decomp.py +950 -0
- fmot-3.16.0/fmot/beta/signal24/gmac_wrappers.py +49 -0
- fmot-3.16.0/fmot/beta/signal24/higher_precision_matmul.py +138 -0
- fmot-3.16.0/fmot/beta/signal24/stft.py +481 -0
- fmot-3.16.0/fmot/configure.py +155 -0
- fmot-3.16.0/fmot/control.py +21 -0
- fmot-3.16.0/fmot/convert/__init__.py +3 -0
- fmot-3.16.0/fmot/convert/_convert_to_qat.py +127 -0
- fmot-3.16.0/fmot/convert/apply_tags.py +70 -0
- fmot-3.16.0/fmot/convert/conversion_api.py +440 -0
- fmot-3.16.0/fmot/convert/default_mappings.py +58 -0
- fmot-3.16.0/fmot/convert/default_patchings.py +346 -0
- fmot-3.16.0/fmot/convert/default_substitutions.py +88 -0
- fmot-3.16.0/fmot/convert/lut_registry.py +200 -0
- fmot-3.16.0/fmot/convert/mapping.py +176 -0
- fmot-3.16.0/fmot/convert/optimizer.py +24 -0
- fmot-3.16.0/fmot/convert/param_manager.py +0 -0
- fmot-3.16.0/fmot/convert/patch_ir.py +1059 -0
- fmot-3.16.0/fmot/convert/patching.py +133 -0
- fmot-3.16.0/fmot/convert/prune_reparametrization.py +123 -0
- fmot-3.16.0/fmot/convert/quantizer_manager.py +97 -0
- fmot-3.16.0/fmot/convert/substitution.py +85 -0
- fmot-3.16.0/fmot/exceptions.py +28 -0
- fmot-3.16.0/fmot/execute_code.py +69 -0
- fmot-3.16.0/fmot/fqir/__init__.py +22 -0
- fmot-3.16.0/fmot/fqir/_cpp_runtime.cpp +42455 -0
- fmot-3.16.0/fmot/fqir/cpp_backend.py +350 -0
- fmot-3.16.0/fmot/fqir/graph_proto/__init__.py +1 -0
- fmot-3.16.0/fmot/fqir/graph_proto/graph_proto.py +745 -0
- fmot-3.16.0/fmot/fqir/graph_proto/graph_runtime.py +188 -0
- fmot-3.16.0/fmot/fqir/metadata.py +195 -0
- fmot-3.16.0/fmot/fqir/multigraph/__init__.py +1 -0
- fmot-3.16.0/fmot/fqir/multigraph/dynamic_parameter.py +71 -0
- fmot-3.16.0/fmot/fqir/nodes/__init__.py +3 -0
- fmot-3.16.0/fmot/fqir/nodes/node_base.py +157 -0
- fmot-3.16.0/fmot/fqir/nodes/node_proto.py +140 -0
- fmot-3.16.0/fmot/fqir/nodes/opcount.py +85 -0
- fmot-3.16.0/fmot/fqir/nodes/opcounters.py +662 -0
- fmot-3.16.0/fmot/fqir/nodes/optype_base.py +252 -0
- fmot-3.16.0/fmot/fqir/nodes/optypes.py +2077 -0
- fmot-3.16.0/fmot/fqir/passes/__init__.py +3 -0
- fmot-3.16.0/fmot/fqir/passes/batchdim_removal.py +306 -0
- fmot-3.16.0/fmot/fqir/passes/cleanup.py +115 -0
- fmot-3.16.0/fmot/fqir/passes/conv1d_weight_pass.py +37 -0
- fmot-3.16.0/fmot/fqir/passes/dimtag_removal.py +15 -0
- fmot-3.16.0/fmot/fqir/passes/fold_reused_params.py +62 -0
- fmot-3.16.0/fmot/fqir/passes/helpers.py +115 -0
- fmot-3.16.0/fmot/fqir/passes/kernel_inlining.py +24 -0
- fmot-3.16.0/fmot/fqir/passes/kernelize_lstm.py +799 -0
- fmot-3.16.0/fmot/fqir/passes/kernelize_lut.py +187 -0
- fmot-3.16.0/fmot/fqir/passes/kernelize_red_broad.py +199 -0
- fmot-3.16.0/fmot/fqir/passes/kernelize_temporal_unfold.py +128 -0
- fmot-3.16.0/fmot/fqir/passes/output_naming.py +55 -0
- fmot-3.16.0/fmot/fqir/passes/pass_infrastruce.py +66 -0
- fmot-3.16.0/fmot/fqir/passes/repeat_assign.py +42 -0
- fmot-3.16.0/fmot/fqir/passes/statically_transpose.py +92 -0
- fmot-3.16.0/fmot/fqir/passes/stride_optimization.py +518 -0
- fmot-3.16.0/fmot/fqir/passes/virtualize_high_precisions.py +2281 -0
- fmot-3.16.0/fmot/fqir/runtime_backend.py +136 -0
- fmot-3.16.0/fmot/fqir/runtime_benchmark.py +234 -0
- fmot-3.16.0/fmot/fqir/runtime_plan.py +259 -0
- fmot-3.16.0/fmot/fqir/utilities/__init__.py +0 -0
- fmot-3.16.0/fmot/fqir/utilities/set_signature.py +23 -0
- fmot-3.16.0/fmot/fqir/utils.py +28 -0
- fmot-3.16.0/fmot/fqir/variables/__init__.py +2 -0
- fmot-3.16.0/fmot/fqir/variables/tensor_proto.py +227 -0
- fmot-3.16.0/fmot/fqir/variables/variable_base.py +75 -0
- fmot-3.16.0/fmot/fqir/writer/__init__.py +4 -0
- fmot-3.16.0/fmot/fqir/writer/barni.py +39 -0
- fmot-3.16.0/fmot/fqir/writer/divisionlib.py +313 -0
- fmot-3.16.0/fmot/fqir/writer/fftlib.py +674 -0
- fmot-3.16.0/fmot/fqir/writer/fqir_writer.py +3757 -0
- fmot-3.16.0/fmot/fqir/writer/graph_splitting.py +345 -0
- fmot-3.16.0/fmot/fqir/writer/kernels/__init__.py +3 -0
- fmot-3.16.0/fmot/fqir/writer/kernels/biquad.py +118 -0
- fmot-3.16.0/fmot/fqir/writer/kernels/distributed_flat_linear.py +162 -0
- fmot-3.16.0/fmot/fqir/writer/kernels/fir.py +76 -0
- fmot-3.16.0/fmot/fqir/writer/loop_nesting.py +320 -0
- fmot-3.16.0/fmot/fqir/writer/optimizations/__init__.py +2 -0
- fmot-3.16.0/fmot/fqir/writer/optimizations/assign_legalizer.py +50 -0
- fmot-3.16.0/fmot/fqir/writer/optimizations/broadcast_vvmul.py +56 -0
- fmot-3.16.0/fmot/fqir/writer/pooling.py +106 -0
- fmot-3.16.0/fmot/fqir/writer/softmax.py +52 -0
- fmot-3.16.0/fmot/fqir/writer/utils.py +373 -0
- fmot-3.16.0/fmot/functional.py +165 -0
- fmot-3.16.0/fmot/iospec.py +61 -0
- fmot-3.16.0/fmot/model_templates/__init__.py +2 -0
- fmot-3.16.0/fmot/model_templates/tiny_lstm.py +163 -0
- fmot-3.16.0/fmot/model_templates/wwd_arch.py +134 -0
- fmot-3.16.0/fmot/nn/__init__.py +28 -0
- fmot-3.16.0/fmot/nn/atomics.py +604 -0
- fmot-3.16.0/fmot/nn/band_transforms.py +319 -0
- fmot-3.16.0/fmot/nn/bandrnn.py +887 -0
- fmot-3.16.0/fmot/nn/blockrnn.py +691 -0
- fmot-3.16.0/fmot/nn/composites.py +528 -0
- fmot-3.16.0/fmot/nn/conv.py +372 -0
- fmot-3.16.0/fmot/nn/cumulative_linear.py +175 -0
- fmot-3.16.0/fmot/nn/derived_param.py +52 -0
- fmot-3.16.0/fmot/nn/femtornn.py +596 -0
- fmot-3.16.0/fmot/nn/fft/__init__.py +10 -0
- fmot-3.16.0/fmot/nn/fft/fft.py +174 -0
- fmot-3.16.0/fmot/nn/fft/fft_v1.py +543 -0
- fmot-3.16.0/fmot/nn/fft/fft_v2.py +439 -0
- fmot-3.16.0/fmot/nn/fft/stft.py +1018 -0
- fmot-3.16.0/fmot/nn/functional.py +219 -0
- fmot-3.16.0/fmot/nn/gtools.py +183 -0
- fmot-3.16.0/fmot/nn/loop.py +198 -0
- fmot-3.16.0/fmot/nn/sequenced_rnn.py +1047 -0
- fmot-3.16.0/fmot/nn/sequencer.py +325 -0
- fmot-3.16.0/fmot/nn/signal_processing.py +723 -0
- fmot-3.16.0/fmot/nn/sliding_attention.py +122 -0
- fmot-3.16.0/fmot/nn/sparsifiers.py +258 -0
- fmot-3.16.0/fmot/nn/special_rnn.py +268 -0
- fmot-3.16.0/fmot/nn/sru.py +89 -0
- fmot-3.16.0/fmot/nn/super_structures.py +16 -0
- fmot-3.16.0/fmot/nn/temporal_unfold.py +48 -0
- fmot-3.16.0/fmot/nn/transposed_conv1d.py +274 -0
- fmot-3.16.0/fmot/nn/transposed_conv2d.py +178 -0
- fmot-3.16.0/fmot/onnx2fqir/__init__.py +29 -0
- fmot-3.16.0/fmot/onnx2fqir/add_debug_outputs.py +62 -0
- fmot-3.16.0/fmot/onnx2fqir/converters/__init__.py +3 -0
- fmot-3.16.0/fmot/onnx2fqir/converters/custom_rewriters/__init__.py +4 -0
- fmot-3.16.0/fmot/onnx2fqir/converters/custom_rewriters/rewriters.py +152 -0
- fmot-3.16.0/fmot/onnx2fqir/converters/quantize_wrapper.py +98 -0
- fmot-3.16.0/fmot/onnx2fqir/converters/streaming_tdnn.py +1039 -0
- fmot-3.16.0/fmot/onnx2fqir/converters/tflite_tdnn_to_onnx.py +782 -0
- fmot-3.16.0/fmot/onnx2fqir/main.py +351 -0
- fmot-3.16.0/fmot/onnx2fqir/parsing.py +422 -0
- fmot-3.16.0/fmot/onnx2fqir/tflite_digraph.py +260 -0
- fmot-3.16.0/fmot/onnx2fqir/tflite_patterns.py +395 -0
- fmot-3.16.0/fmot/precisions.py +33 -0
- fmot-3.16.0/fmot/qat/__init__.py +14 -0
- fmot-3.16.0/fmot/qat/annotated_tensors.py +243 -0
- fmot-3.16.0/fmot/qat/bitwidths.py +54 -0
- fmot-3.16.0/fmot/qat/control.py +234 -0
- fmot-3.16.0/fmot/qat/fake_quantization.py +85 -0
- fmot-3.16.0/fmot/qat/nn/__init__.py +12 -0
- fmot-3.16.0/fmot/qat/nn/_utils.py +12 -0
- fmot-3.16.0/fmot/qat/nn/act_density.py +107 -0
- fmot-3.16.0/fmot/qat/nn/atomics.py +1916 -0
- fmot-3.16.0/fmot/qat/nn/composites.py +306 -0
- fmot-3.16.0/fmot/qat/nn/density_matmul.py +341 -0
- fmot-3.16.0/fmot/qat/nn/derived_param.py +92 -0
- fmot-3.16.0/fmot/qat/nn/kernel_atomics.py +219 -0
- fmot-3.16.0/fmot/qat/nn/linear.py +293 -0
- fmot-3.16.0/fmot/qat/nn/luts.py +682 -0
- fmot-3.16.0/fmot/qat/nn/norm.py +125 -0
- fmot-3.16.0/fmot/qat/nn/qat_cumulative_linear.py +86 -0
- fmot-3.16.0/fmot/qat/nn/quant_wrap.py +404 -0
- fmot-3.16.0/fmot/qat/nn/quantizers.py +811 -0
- fmot-3.16.0/fmot/qat/nn/sequencer.py +140 -0
- fmot-3.16.0/fmot/qat/nn/temporal_unfold.py +123 -0
- fmot-3.16.0/fmot/sparse/__init__.py +3 -0
- fmot-3.16.0/fmot/sparse/act_pruning.py +93 -0
- fmot-3.16.0/fmot/sparse/pruning.py +305 -0
- fmot-3.16.0/fmot/sparse/pruning_schedulers.py +134 -0
- fmot-3.16.0/fmot/sparse/pruning_utils.py +218 -0
- fmot-3.16.0/fmot/stateful_sequencer.py +24 -0
- fmot-3.16.0/fmot/test/__init__.py +4 -0
- fmot-3.16.0/fmot/test/conftest.py +8 -0
- fmot-3.16.0/fmot/test/ds_tc_resnet.py +230 -0
- fmot-3.16.0/fmot/test/kws_test_library.py +98 -0
- fmot-3.16.0/fmot/test/tcn/__init__.py +0 -0
- fmot-3.16.0/fmot/test/tcn/test_temporal_unfold.py +43 -0
- fmot-3.16.0/fmot/test/test_automp.py +32 -0
- fmot-3.16.0/fmot/test/test_batchnorm.py +43 -0
- fmot-3.16.0/fmot/test/test_conv2d/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_conv2d/test_conv2d.py +114 -0
- fmot-3.16.0/fmot/test/test_conv2d/test_convtranspose2d.py +69 -0
- fmot-3.16.0/fmot/test/test_cqt.py +51 -0
- fmot-3.16.0/fmot/test/test_density_tracking.py +93 -0
- fmot-3.16.0/fmot/test/test_derived_param.py +145 -0
- fmot-3.16.0/fmot/test/test_diagnosis.py +93 -0
- fmot-3.16.0/fmot/test/test_dim_anno.py +106 -0
- fmot-3.16.0/fmot/test/test_dlstm.py +55 -0
- fmot-3.16.0/fmot/test/test_dropout.py +33 -0
- fmot-3.16.0/fmot/test/test_fast_ilut.py +57 -0
- fmot-3.16.0/fmot/test/test_features.py +168 -0
- fmot-3.16.0/fmot/test/test_fqir/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_fqir/test_batch_run.py +96 -0
- fmot-3.16.0/fmot/test/test_fqir/test_broadcast_kern.py +33 -0
- fmot-3.16.0/fmot/test/test_fqir/test_cpp_runtime.py +1236 -0
- fmot-3.16.0/fmot/test/test_fqir/test_cpp_runtime_notebook_regression.py +70 -0
- fmot-3.16.0/fmot/test/test_fqir/test_loop.py +281 -0
- fmot-3.16.0/fmot/test/test_fqir/test_output_names.py +128 -0
- fmot-3.16.0/fmot/test/test_fqir/test_precision_split.py +51 -0
- fmot-3.16.0/fmot/test/test_fqir/test_readme.py +49 -0
- fmot-3.16.0/fmot/test/test_fqir/test_runtime_backend.py +508 -0
- fmot-3.16.0/fmot/test/test_fqir/test_single_ops.py +675 -0
- fmot-3.16.0/fmot/test/test_fqir_step.py +74 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fft.py +0 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fftlib/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fftlib/test_fftlib_fft.py +76 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fftlib/test_stft_istft.py +90 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer/test_comparison_ops.py +48 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer/test_divide.py +187 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer/test_i24_decomp.py +302 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer/test_interleaving.py +51 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer/test_lut_interpolation.py +273 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer/test_softmax.py +40 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer/test_temporal_conv2d.py +185 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer/test_vi_ops.py +143 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer/test_vv_ops.py +93 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer_i16/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer_i16/test_boolean_ops.py +169 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer_i16/test_quantization.py +17 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer_i16/test_reduction.py +75 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_fqir_writer_i16/test_simple_kernels.py +70 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_graph_merging.py +63 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_graph_splitting/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_graph_splitting/test_clara_split.py +40 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_graph_splitting/test_documentation_examples.py +248 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_graph_splitting/test_fqir_splitting.py +168 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_graph_splitting/test_nx_parsing.py +84 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_kernels/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_kernels/design_biquad_filter.py +125 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_kernels/test_biquad.py +341 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_kernels/test_biquad_inline.py +97 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_kernels/test_distrib_flat_linear.py +125 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_loop_nesting/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_loop_nesting/test_loop_nesting.py +202 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_loop_writer/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_loop_writer/test_filters.py +78 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_loop_writer/test_slow_max.py +59 -0
- fmot-3.16.0/fmot/test/test_fqir_writer/test_stitch_examples.py +101 -0
- fmot-3.16.0/fmot/test/test_gmac/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_gmac/test_fqir_virtualization.py +83 -0
- fmot-3.16.0/fmot/test/test_gmac/test_gmac_v2.py +299 -0
- fmot-3.16.0/fmot/test/test_gmac/test_gtools.py +186 -0
- fmot-3.16.0/fmot/test/test_gmac/test_i24_sequencer.py +131 -0
- fmot-3.16.0/fmot/test/test_gmac/test_int24_integration.py +136 -0
- fmot-3.16.0/fmot/test/test_gmac/test_mimo_gmac_state.py +137 -0
- fmot-3.16.0/fmot/test/test_gmac/test_sub.py +51 -0
- fmot-3.16.0/fmot/test/test_gradients/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_gradients/test_atan2.py +16 -0
- fmot-3.16.0/fmot/test/test_gradients/test_beta_fft.py +159 -0
- fmot-3.16.0/fmot/test/test_gradients/test_nonlin_grads.py +78 -0
- fmot-3.16.0/fmot/test/test_input_formats.py +274 -0
- fmot-3.16.0/fmot/test/test_inv_mel.py +54 -0
- fmot-3.16.0/fmot/test/test_iospec/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_iospec/test_simple_iospec.py +50 -0
- fmot-3.16.0/fmot/test/test_layer_reuse.py +72 -0
- fmot-3.16.0/fmot/test/test_layernorm.py +24 -0
- fmot-3.16.0/fmot/test/test_loops/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_loops/test_blockrnn.py +92 -0
- fmot-3.16.0/fmot/test/test_loops/test_i24_loop.py +83 -0
- fmot-3.16.0/fmot/test/test_loops/test_loop_sequencer.py +213 -0
- fmot-3.16.0/fmot/test/test_loops/test_sequential_loops.py +107 -0
- fmot-3.16.0/fmot/test/test_loops/test_simple_fmot_loops.py +432 -0
- fmot-3.16.0/fmot/test/test_lut_grads.py +64 -0
- fmot-3.16.0/fmot/test/test_nn_stft.py +56 -0
- fmot-3.16.0/fmot/test/test_observability/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_observability/test_user_varnames.py +147 -0
- fmot-3.16.0/fmot/test/test_observability/user_varname_example.py +30 -0
- fmot-3.16.0/fmot/test/test_observers.py +134 -0
- fmot-3.16.0/fmot/test/test_onnx2fqir/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_onnx2fqir/test_custom_onnx_conversion.py +272 -0
- fmot-3.16.0/fmot/test/test_onnx2fqir/test_custom_rewriters.py +443 -0
- fmot-3.16.0/fmot/test/test_onnx2fqir/test_documentation_example.py +96 -0
- fmot-3.16.0/fmot/test/test_onnx2fqir/test_roundtrip.py +560 -0
- fmot-3.16.0/fmot/test/test_onnx2fqir/test_tflite_digraph.py +108 -0
- fmot-3.16.0/fmot/test/test_package.py +13 -0
- fmot-3.16.0/fmot/test/test_packer.py +45 -0
- fmot-3.16.0/fmot/test/test_param_reuse.py +55 -0
- fmot-3.16.0/fmot/test/test_precision_mod.py +31 -0
- fmot-3.16.0/fmot/test/test_pruning.py +181 -0
- fmot-3.16.0/fmot/test/test_quant.py +19 -0
- fmot-3.16.0/fmot/test/test_quantile_observer.py +107 -0
- fmot-3.16.0/fmot/test/test_round_config.py +51 -0
- fmot-3.16.0/fmot/test/test_run_sequential_graph.py +93 -0
- fmot-3.16.0/fmot/test/test_saturating_lut.py +65 -0
- fmot-3.16.0/fmot/test/test_sequencers.py +529 -0
- fmot-3.16.0/fmot/test/test_serialization.py +30 -0
- fmot-3.16.0/fmot/test/test_signal/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_signal/test_polar_rect.py +108 -0
- fmot-3.16.0/fmot/test/test_signal/test_signal24/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_signal/test_signal24/test_higher_precision_matmul.py +54 -0
- fmot-3.16.0/fmot/test/test_signal/test_signal24/test_stft_istft.py +94 -0
- fmot-3.16.0/fmot/test/test_signal/test_tuneps.py +59 -0
- fmot-3.16.0/fmot/test/test_state_inheritance.py +102 -0
- fmot-3.16.0/fmot/test/test_stft/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_stft/test_asym_example.py +55 -0
- fmot-3.16.0/fmot/test/test_stft/test_asym_stft_istft.py +62 -0
- fmot-3.16.0/fmot/test/test_stft/test_fft.py +28 -0
- fmot-3.16.0/fmot/test/test_stft/test_ifft.py +75 -0
- fmot-3.16.0/fmot/test/test_stft/test_stft.py +159 -0
- fmot-3.16.0/fmot/test/test_stft/test_stft_v2.py +126 -0
- fmot-3.16.0/fmot/test/test_stft/test_stft_winhop.py +29 -0
- fmot-3.16.0/fmot/test/test_stride_optim.py +86 -0
- fmot-3.16.0/fmot/test/test_superstructure_dict.py +88 -0
- fmot-3.16.0/fmot/test/test_superstructure_list_dict.py +70 -0
- fmot-3.16.0/fmot/test/test_superstructure_lists.py +139 -0
- fmot-3.16.0/fmot/test/test_tags/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_tags/test_dont_round.py +84 -0
- fmot-3.16.0/fmot/test/test_tdnn/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_tdnn/test_distributed_flat_linear.py +59 -0
- fmot-3.16.0/fmot/test/test_tdnn/test_docstring.py +46 -0
- fmot-3.16.0/fmot/test/test_templates.py +65 -0
- fmot-3.16.0/fmot/test/test_tf_pruning/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_tf_pruning/test_scheduler_sparsity.py +627 -0
- fmot-3.16.0/fmot/test/test_tilut.py +49 -0
- fmot-3.16.0/fmot/test/test_unet.py +188 -0
- fmot-3.16.0/fmot/test/test_user_integer_io/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_user_integer_io/test_fixed_quanta_obs.py +23 -0
- fmot-3.16.0/fmot/test/test_user_integer_io/test_fqir_integer_runtime.py +38 -0
- fmot-3.16.0/fmot/test/test_user_integer_io/test_input_signature.py +22 -0
- fmot-3.16.0/fmot/test/test_user_integer_io/test_integer_runtime_with_vi.py +40 -0
- fmot-3.16.0/fmot/test/test_user_integer_io/test_quant_specification_perf.py +59 -0
- fmot-3.16.0/fmot/test/test_user_integer_io/test_quanta_io_specification.py +243 -0
- fmot-3.16.0/fmot/test/test_workloads/__init__.py +0 -0
- fmot-3.16.0/fmot/test/test_workloads/test_reused_tcn.py +117 -0
- fmot-3.16.0/fmot/test/utm/__init__.py +3 -0
- fmot-3.16.0/fmot/test/utm/atomic_test_library.py +567 -0
- fmot-3.16.0/fmot/test/utm/feedforward_test_library.py +302 -0
- fmot-3.16.0/fmot/test/utm/get_utms.py +34 -0
- fmot-3.16.0/fmot/test/utm/plot_errors.py +83 -0
- fmot-3.16.0/fmot/test/utm/quant_tolerances.py +131 -0
- fmot-3.16.0/fmot/test/utm/rnn_test_library.py +516 -0
- fmot-3.16.0/fmot/test/utm/run_utm.py +41 -0
- fmot-3.16.0/fmot/test/utm/test_utm_converted_runtime.py +7 -0
- fmot-3.16.0/fmot/test/utm/test_utm_fqir_runtime.py +24 -0
- fmot-3.16.0/fmot/test/utm/test_utm_mixed_precision.py +12 -0
- fmot-3.16.0/fmot/test/utm/test_utm_quantization_error.py +25 -0
- fmot-3.16.0/fmot/test/utm/unittest_objects.py +451 -0
- fmot-3.16.0/fmot/tf/__init__.py +1 -0
- fmot-3.16.0/fmot/tf/sparse/__init__.py +9 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/__init__.py +0 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/__init__.py +0 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/keras/__init__.py +0 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/keras/compat.py +134 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/keras/metrics.py +95 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/keras/utils.py +55 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/sparsity/__init__.py +0 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/sparsity/keras/__init__.py +3 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/sparsity/keras/prunable_layer.py +39 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/sparsity/keras/prune.py +286 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/sparsity/keras/prune_registry.py +271 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/sparsity/keras/pruning_callbacks.py +141 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/sparsity/keras/pruning_impl.py +351 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/sparsity/keras/pruning_schedule.py +272 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/sparsity/keras/pruning_utils.py +382 -0
- fmot-3.16.0/fmot/tf/sparse/_tfmot/core/sparsity/keras/pruning_wrapper.py +427 -0
- fmot-3.16.0/fmot/tf/sparse/notebooks/__init__.py +0 -0
- fmot-3.16.0/fmot/tf/sparse/plot.py +167 -0
- fmot-3.16.0/fmot/tf/sparse/prune.py +271 -0
- fmot-3.16.0/fmot/tf/sparse/pruning_schedulers/__init__.py +0 -0
- fmot-3.16.0/fmot/tf/sparse/pruning_schedulers/linear_scheduler.py +63 -0
- fmot-3.16.0/fmot/tf/sparse/pruning_schedulers/sine_scheduler.py +68 -0
- fmot-3.16.0/fmot/tf/sparse/spu_pruning_wrappers.py +432 -0
- fmot-3.16.0/fmot/torchscript_utils.py +493 -0
- fmot-3.16.0/fmot/tracing/__init__.py +5 -0
- fmot-3.16.0/fmot/tracing/compare_fqir.py +117 -0
- fmot-3.16.0/fmot/tracing/oplinks_v1.py +42 -0
- fmot-3.16.0/fmot/tracing/tracing.py +1053 -0
- fmot-3.16.0/fmot/tracing/tracing_blacklist.py +20 -0
- fmot-3.16.0/fmot/tracing/utils.py +100 -0
- fmot-3.16.0/fmot/utils/__init__.py +12 -0
- fmot-3.16.0/fmot/utils/activity.py +135 -0
- fmot-3.16.0/fmot/utils/conv1d_utils.py +121 -0
- fmot-3.16.0/fmot/utils/param_manager.py +79 -0
- fmot-3.16.0/fmot/utils/quant_diagnostic.py +202 -0
- fmot-3.16.0/fmot/utils/quant_tools/__init__.py +1 -0
- fmot-3.16.0/fmot/utils/quant_tools/diagnosis.py +197 -0
- fmot-3.16.0/fmot/utils/quantizer_manager.py +67 -0
- fmot-3.16.0/fmot/utils/rich_attr.py +16 -0
- fmot-3.16.0/fmot/utils/saturation_opt.py +257 -0
- fmot-3.16.0/fmot/utils/serialization.py +41 -0
- fmot-3.16.0/fmot/utils/typing.py +4 -0
- fmot-3.16.0/fmot.egg-info/PKG-INFO +62 -0
- fmot-3.16.0/fmot.egg-info/SOURCES.txt +399 -0
- fmot-3.16.0/fmot.egg-info/dependency_links.txt +1 -0
- fmot-3.16.0/fmot.egg-info/not-zip-safe +1 -0
- fmot-3.16.0/fmot.egg-info/requires.txt +24 -0
- fmot-3.16.0/fmot.egg-info/top_level.txt +1 -0
- fmot-3.16.0/pyproject.toml +14 -0
- fmot-3.16.0/setup.cfg +4 -0
- fmot-3.16.0/setup.py +134 -0
fmot-3.16.0/LICENSE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright (c) 2024 Femtosense, Inc.
|
fmot-3.16.0/MANIFEST.in
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
include NAME
|
|
2
|
+
include LICENSE
|
|
3
|
+
include *.yml
|
|
4
|
+
include */VERSION
|
|
5
|
+
include */ENV_REQUIREMENTS.sh
|
|
6
|
+
include */PY_REQUIREMENTS
|
|
7
|
+
include */*_REQUIREMENTS
|
|
8
|
+
include pyproject.toml
|
|
9
|
+
recursive-include * *.c
|
|
10
|
+
exclude obfuscation_cfg.yaml
|
|
11
|
+
exclude obfuscate.py
|
|
12
|
+
include *.wav
|
fmot-3.16.0/NAME
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fmot
|
fmot-3.16.0/PKG-INFO
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fmot
|
|
3
|
+
Version: 3.16.0
|
|
4
|
+
Summary: Femtosense Model Optimization Toolkit
|
|
5
|
+
Home-page: https://github.com/femtosense/fmot
|
|
6
|
+
Author: Femtosense
|
|
7
|
+
Author-email: info@femtosense.ai
|
|
8
|
+
Project-URL: Source, https://github.com/femtosense/fmot
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Requires-Python: >=3.6
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: Cython
|
|
22
|
+
Requires-Dist: torch>=1.12.1
|
|
23
|
+
Requires-Dist: numpy>=2.0
|
|
24
|
+
Requires-Dist: scipy<1.17
|
|
25
|
+
Requires-Dist: python_speech_features
|
|
26
|
+
Requires-Dist: tqdm
|
|
27
|
+
Requires-Dist: networkx
|
|
28
|
+
Requires-Dist: deprecation
|
|
29
|
+
Requires-Dist: tabulate
|
|
30
|
+
Requires-Dist: colorcet
|
|
31
|
+
Requires-Dist: matplotlib
|
|
32
|
+
Requires-Dist: pandas
|
|
33
|
+
Requires-Dist: pyyaml
|
|
34
|
+
Requires-Dist: ordered_set==4.1.0
|
|
35
|
+
Requires-Dist: femtorun>=1.1.6
|
|
36
|
+
Provides-Extra: onnx2fqir
|
|
37
|
+
Requires-Dist: onnx; extra == "onnx2fqir"
|
|
38
|
+
Requires-Dist: onnxruntime; extra == "onnx2fqir"
|
|
39
|
+
Requires-Dist: tensorflow; extra == "onnx2fqir"
|
|
40
|
+
Provides-Extra: tf
|
|
41
|
+
Requires-Dist: tensorflow; extra == "tf"
|
|
42
|
+
Requires-Dist: tf-keras; extra == "tf"
|
|
43
|
+
Dynamic: author
|
|
44
|
+
Dynamic: author-email
|
|
45
|
+
Dynamic: classifier
|
|
46
|
+
Dynamic: description
|
|
47
|
+
Dynamic: description-content-type
|
|
48
|
+
Dynamic: home-page
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
Dynamic: project-url
|
|
51
|
+
Dynamic: provides-extra
|
|
52
|
+
Dynamic: requires-dist
|
|
53
|
+
Dynamic: requires-python
|
|
54
|
+
Dynamic: summary
|
|
55
|
+
|
|
56
|
+

|
|
57
|
+
|
|
58
|
+
# fmot
|
|
59
|
+
The Femtosense Model Optimization Toolkit (fmot) quantizes neural network models from PyTorch for deployment on Femtosense hardware.
|
|
60
|
+
|
|
61
|
+
See the documentation at [fmot.femtosense.ai](fmot.femtosense.ai) for more details.
|
|
62
|
+
|
fmot-3.16.0/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# fmot
|
|
4
|
+
The Femtosense Model Optimization Toolkit (fmot) quantizes neural network models from PyTorch for deployment on Femtosense hardware.
|
|
5
|
+
|
|
6
|
+
See the documentation at [fmot.femtosense.ai](fmot.femtosense.ai) for more details.
|
|
7
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# You can put arbitrary shell commands in here.
|
|
4
|
+
# Docker will also make use of these commands, so these must work in docker.
|
|
5
|
+
# Think hard before introducing these kind of dependencies.
|
|
6
|
+
|
|
7
|
+
function mac_install {
|
|
8
|
+
# install function for mac
|
|
9
|
+
# Check if already installed and install if not
|
|
10
|
+
brew list ${1} || brew install ${1}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function ubuntu_install {
|
|
14
|
+
# install function for mac
|
|
15
|
+
# Check if already installed and install if not
|
|
16
|
+
dpkg -s ${1} || apt-get install -y ${1}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# install packages. Unfortunately there is different method for each OS
|
|
20
|
+
if [[ ${OSTYPE} == "linux"* ]]; then
|
|
21
|
+
DISTRO=$(awk -F= '/^ID=/{print $2}' /etc/os-release)
|
|
22
|
+
|
|
23
|
+
if [[ ${DISTRO} == *"ubuntu"* ]]; then :
|
|
24
|
+
# ==================== Ubuntu dependencies here ====================
|
|
25
|
+
# ubuntu_install htop
|
|
26
|
+
# ==================================================================
|
|
27
|
+
|
|
28
|
+
elif [[ ${DISTRO} == *"centos"* ]] ; then :
|
|
29
|
+
# ==================== CentOS dependencies here ====================
|
|
30
|
+
# yum install -y htop
|
|
31
|
+
# ==================================================================
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
elif [[ ${OSTYPE} == "darwin"* ]]; then :
|
|
35
|
+
# ==================== mac dependencies here =======================
|
|
36
|
+
# mac_install htop
|
|
37
|
+
# ==================================================================
|
|
38
|
+
fi
|
fmot-3.16.0/fmot/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.16.0
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
def _get_dir():
|
|
2
|
+
import pathlib
|
|
3
|
+
|
|
4
|
+
return pathlib.Path(__file__).parent.resolve()
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
__version__ = (_get_dir() / "VERSION").read_text(encoding="utf-8").strip()
|
|
8
|
+
|
|
9
|
+
import torch
|
|
10
|
+
from . import torchscript_utils
|
|
11
|
+
from . import configure
|
|
12
|
+
from .configure import CONFIG, ROUND_CONFIG
|
|
13
|
+
from . import nn
|
|
14
|
+
from . import qat, utils, convert, tracing
|
|
15
|
+
from ._open_docs import open_docs
|
|
16
|
+
from ._supported_ops import supported_ops, conversion_branch
|
|
17
|
+
from .convert.conversion_api import ConvertedModel
|
|
18
|
+
from .convert.lut_registry import LUT_REGISTRY, register_lut, LUTConfig
|
|
19
|
+
from .utils import save, load
|
|
20
|
+
from .sparse import *
|
|
21
|
+
from .beta import *
|
|
22
|
+
from . import fqir
|
|
23
|
+
from .stateful_sequencer import set_sequencer_p_inherit
|
|
24
|
+
from .control import *
|
|
25
|
+
from .functional import tag
|
|
26
|
+
from . import precisions
|
|
27
|
+
from .precisions import int24, int16, int8, Precision
|
|
28
|
+
from .iospec import iospec_from_fqir
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import fmot
|
|
2
|
+
import os
|
|
3
|
+
import pathlib
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def open_docs():
|
|
7
|
+
fmot_path = pathlib.Path(fmot.__file__).parent.resolve().parent.resolve()
|
|
8
|
+
doc_path = os.path.join(fmot_path, "docs")
|
|
9
|
+
index_path = os.path.join(doc_path, "_build", "html", "index.html")
|
|
10
|
+
cwd = os.getcwd()
|
|
11
|
+
os.system(
|
|
12
|
+
f"cd {doc_path}; sphinx-apidoc -f . -o .; make clean html; cd {cwd}; open {index_path}"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
open_docs()
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
from fmot.convert.default_patchings import DEFAULT_PATCHINGS, PatchRule
|
|
2
|
+
from fmot.convert.default_mappings import DEFAULT_MAPPINGS
|
|
3
|
+
from fmot.convert.default_substitutions import DEFAULT_SUBSTITUTIONS
|
|
4
|
+
from fmot.convert.lut_registry import LUT_REGISTRY
|
|
5
|
+
import inspect
|
|
6
|
+
from torch import nn
|
|
7
|
+
import fmot
|
|
8
|
+
import types
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def iter_nn_module_beneath_package(module: types.ModuleType, depth: int):
|
|
12
|
+
"""Automatically yields all of the nn.Module layers under
|
|
13
|
+
a given package (e.g. fmot.nn)"""
|
|
14
|
+
assert isinstance(module, types.ModuleType)
|
|
15
|
+
for value in module.__dict__.values():
|
|
16
|
+
if isinstance(value, type) and issubclass(value, nn.Module):
|
|
17
|
+
yield value
|
|
18
|
+
# elif isinstance(value, types.ModuleType) and depth > 0:
|
|
19
|
+
# if "fmot" in value.__file__:
|
|
20
|
+
# for x in iter_nn_module_beneath_package(value, depth-1):
|
|
21
|
+
# yield x
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def supported_ops():
|
|
25
|
+
"""
|
|
26
|
+
Returns a list of supported operations.
|
|
27
|
+
"""
|
|
28
|
+
sops = set()
|
|
29
|
+
|
|
30
|
+
# iterate over all of the substitutions
|
|
31
|
+
for m in DEFAULT_SUBSTITUTIONS:
|
|
32
|
+
# if m.__module__.startswith("torch"):
|
|
33
|
+
sops.add(m)
|
|
34
|
+
|
|
35
|
+
# iterate over all of the patchings, ensuring that there is an available mapping
|
|
36
|
+
for k, v in DEFAULT_PATCHINGS.items():
|
|
37
|
+
if isinstance(v, PatchRule):
|
|
38
|
+
patchings = v.options
|
|
39
|
+
else:
|
|
40
|
+
patchings = [v]
|
|
41
|
+
sops.add(k)
|
|
42
|
+
|
|
43
|
+
# iterate over all of the mappings, add mappings that start with builtin modules
|
|
44
|
+
for m in DEFAULT_MAPPINGS:
|
|
45
|
+
if m.__module__.startswith("torch"):
|
|
46
|
+
sops.add(m)
|
|
47
|
+
elif hasattr(m, "report_supported") and m.report_supported:
|
|
48
|
+
sops.add(m)
|
|
49
|
+
|
|
50
|
+
for m in iter_nn_module_beneath_package(fmot.nn, depth=3):
|
|
51
|
+
if hasattr(m, "report_supported") and m.report_supported:
|
|
52
|
+
sops.add(m)
|
|
53
|
+
|
|
54
|
+
for m in LUT_REGISTRY:
|
|
55
|
+
sops.add(m)
|
|
56
|
+
|
|
57
|
+
return list(sops)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def typename(x):
|
|
61
|
+
if isinstance(x, type):
|
|
62
|
+
s = str(x)
|
|
63
|
+
return s.split("'")[1]
|
|
64
|
+
else:
|
|
65
|
+
return x
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def conversion_branch(op):
|
|
69
|
+
branch = [op]
|
|
70
|
+
if inspect.isfunction(op):
|
|
71
|
+
assert op.__module__ == "torch.nn.functional"
|
|
72
|
+
op = "F." + op.__name__
|
|
73
|
+
branch = [op]
|
|
74
|
+
elif type(op).__name__ == "builtin_function_or_method":
|
|
75
|
+
name = op.__name__
|
|
76
|
+
op = "aten::" + name
|
|
77
|
+
branch = ["torch." + name, op]
|
|
78
|
+
if op in DEFAULT_PATCHINGS:
|
|
79
|
+
op = DEFAULT_PATCHINGS[op]
|
|
80
|
+
if isinstance(op, PatchRule):
|
|
81
|
+
op = op.options[0]
|
|
82
|
+
branch += [op]
|
|
83
|
+
if op in DEFAULT_MAPPINGS:
|
|
84
|
+
op = DEFAULT_MAPPINGS[op]
|
|
85
|
+
branch += [op]
|
|
86
|
+
else:
|
|
87
|
+
branch += ["patched", "mapped"]
|
|
88
|
+
return " -> ".join([typename(n) for n in branch])
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if __name__ == "__main__":
|
|
92
|
+
print(list(iter_nn_module_beneath_package(fmot.nn, depth=3)))
|
|
93
|
+
# print(fmot.nn.__file__)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
from torch import nn
|
|
3
|
+
import fmot
|
|
4
|
+
from fmot.beta import QuantizationErrorAnalyzer
|
|
5
|
+
|
|
6
|
+
if __name__ == "__main__":
|
|
7
|
+
model = nn.Sequential(
|
|
8
|
+
fmot.nn.TemporalConv1d(32, 64, kernel_size=1),
|
|
9
|
+
nn.ReLU(),
|
|
10
|
+
fmot.nn.TemporalConv1d(64, 64, kernel_size=3, groups=64),
|
|
11
|
+
nn.ReLU(),
|
|
12
|
+
fmot.nn.TemporalConv1d(64, 32, kernel_size=1),
|
|
13
|
+
fmot.nn.TemporalConv1d(32, 64, kernel_size=1),
|
|
14
|
+
nn.ReLU(),
|
|
15
|
+
fmot.nn.TemporalConv1d(64, 64, kernel_size=3, groups=64),
|
|
16
|
+
nn.ReLU(),
|
|
17
|
+
fmot.nn.TemporalConv1d(64, 32, kernel_size=1),
|
|
18
|
+
fmot.nn.TemporalConv1d(32, 64, kernel_size=1),
|
|
19
|
+
nn.ReLU(),
|
|
20
|
+
fmot.nn.TemporalConv1d(64, 64, kernel_size=3, groups=64),
|
|
21
|
+
nn.ReLU(),
|
|
22
|
+
fmot.nn.TemporalConv1d(64, 32, kernel_size=1),
|
|
23
|
+
nn.Sigmoid(),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
cmodel = fmot.ConvertedModel(model, batch_dim=0, seq_dim=2)
|
|
27
|
+
cmodel.quantize([torch.randn(8, 32, 32) for _ in range(4)])
|
|
28
|
+
|
|
29
|
+
analyzer = QuantizationErrorAnalyzer(cmodel, (torch.randn(8, 32, 32),))
|
|
30
|
+
analyzer.plot_qsnr(show=True)
|
|
31
|
+
analyzer.plot_dynamic_range_utilization(show=True, fname="dyn_util.png")
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
from fmot.exceptions import ConversionDependencyError
|
|
2
|
+
from . import auto_multiprecision
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def optimize_mixed_precision(
|
|
6
|
+
cmodel,
|
|
7
|
+
objective,
|
|
8
|
+
eta,
|
|
9
|
+
inputs,
|
|
10
|
+
targets,
|
|
11
|
+
niter=1,
|
|
12
|
+
loss_type="polynomial",
|
|
13
|
+
device="cpu",
|
|
14
|
+
**kwargs
|
|
15
|
+
):
|
|
16
|
+
r"""Heuristic search for an optimal mixed-precision configuration.
|
|
17
|
+
|
|
18
|
+
A mixed-precision configuration uses different integer bitwidths throughout
|
|
19
|
+
the model to reduce computational latency and energy when deployed in
|
|
20
|
+
hardware.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
objective (callable): Objective function to co-minimize with energy.
|
|
24
|
+
Must have the signature :attr:`fn(output, target)` where
|
|
25
|
+
:attr:`output` is the model output and :attr:`target` is a
|
|
26
|
+
ground truth target. Must also return a single value.
|
|
27
|
+
eta (float): A hyperparameter between 0 and 1 to tune the relative weighting between
|
|
28
|
+
the objective function and energy minimization
|
|
29
|
+
inputs (list[Tensor] or list[tuple[Tensor]]): A set of inputs to the model.
|
|
30
|
+
If the model takes multiple inputs, :attr:`inputs` can be a list of tuples of
|
|
31
|
+
tensors, where each tuple holds a set of model inputs.
|
|
32
|
+
targets (list[Tensor]): A set of ground-truth targets; should be the same length and
|
|
33
|
+
1-to-1 with :attr:`inputs`. Used as the second argument to :attr:`objective`.
|
|
34
|
+
niter (int): Number of iterations of the optimization algorithm. Default is 1.
|
|
35
|
+
ramp_eta (bool): If true, :attr:`eta` will be linearly ramped over
|
|
36
|
+
the course of the :attr:`niter` repetitions. Default is True.
|
|
37
|
+
loss_type (str): :attr:`'polynomial'`, :attr:`'logarithmic'`, or
|
|
38
|
+
:attr:`'exponential'`. :attr:`polynomial` is the default. :attr:`logarithmic`
|
|
39
|
+
should be used for loss functions that are logarithmic with the model's
|
|
40
|
+
performance, such as cross-entropy, kl-divergence, and signal-to-noise-ratio.
|
|
41
|
+
:attr:`polynomial` should used if the loss function is linear or polynomial with
|
|
42
|
+
the model's performance, such as mean-squared-error, accuracy, F1, precision,
|
|
43
|
+
and recall.
|
|
44
|
+
num_inputs_per_step (int): number of inputs to use for each step of optimization.
|
|
45
|
+
Default is :attr:`None`, in which case the objective will be averaged on
|
|
46
|
+
all of the provided inputs and targets for each step of optimization. For
|
|
47
|
+
large models and/or large sets of inputs/targets, this can be prohibitively
|
|
48
|
+
slow, in which case a subset of the inputs/targets of size
|
|
49
|
+
:attr:`num_inputs_per_step` can be used.
|
|
50
|
+
device (str or :class:`torch.device`): Device that model is on. Default is 'cpu'.
|
|
51
|
+
|
|
52
|
+
The mixed-precision-optimization algorithm tries to co-minimize the objective
|
|
53
|
+
function with the model's energy. The overall objective is:
|
|
54
|
+
|
|
55
|
+
.. math::
|
|
56
|
+
|
|
57
|
+
C = (1-\eta)*\tilde{L}(y, \hat{y}) + \eta * \tilde{E}(model)
|
|
58
|
+
|
|
59
|
+
Here, :math:`\tilde{L}(y, \hat{y})` is the function provided as :attr:`objective`, normalized
|
|
60
|
+
and rescaled so that the most aggressively quantized version of the model gets a
|
|
61
|
+
value of 0 and the least aggressively quantized version of the model gets a value of
|
|
62
|
+
1. :math:`\tilde{E}(model)` is a rough energy estimate of the model's energy consumption,
|
|
63
|
+
rescaled between 0 and 1.
|
|
64
|
+
|
|
65
|
+
Mixed-precision-optimization will affect the model in-place, but the model can
|
|
66
|
+
always be reverted back by calling `modify_precision` or
|
|
67
|
+
calling mixed-precision-optimization again with different parameters.
|
|
68
|
+
"""
|
|
69
|
+
if not cmodel.quantized:
|
|
70
|
+
raise ConversionDependencyError(
|
|
71
|
+
"Model must be quantized before optimizing mixed-precision config."
|
|
72
|
+
+ " Call `.quantize()` first"
|
|
73
|
+
)
|
|
74
|
+
model, energy, loss = auto_multiprecision.optimize_mixed_precision(
|
|
75
|
+
cmodel,
|
|
76
|
+
cmodel,
|
|
77
|
+
objective=objective,
|
|
78
|
+
eta=eta,
|
|
79
|
+
inputs=inputs,
|
|
80
|
+
targets=targets,
|
|
81
|
+
niter=niter,
|
|
82
|
+
ramp_eta=True,
|
|
83
|
+
loss_type=loss_type,
|
|
84
|
+
device=device,
|
|
85
|
+
**kwargs
|
|
86
|
+
)
|
|
87
|
+
return energy, loss
|