sc2bench.analysisο
- sc2bench.analysis.register_analysis_class(cls)[source]ο
Registers an analyzer class.
- Parameters:
cls (class) β analyzer class to be registered
- Returns:
registered analyzer class
- Return type:
class
- class sc2bench.analysis.AnalyzableModule(analyzer_configs=None)[source]ο
A base module to analyze and summarize the wrapped modules and intermediate representations.
- Parameters:
analyzer_configs (list[dict] or None) β list of analysis configurations
- forward(*args, **kwargs)[source]ο
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class sc2bench.analysis.BaseAnalyzer[source]ο
A base analyzer to analyze and summarize the wrapped modules and intermediate representations.
- class sc2bench.analysis.FileSizeAnalyzer(unit='KB', **kwargs)[source]ο
An analyzer to measure file size of compressed object in the designated unit.
- Parameters:
unit (str) β unit of data size in bytes (βBβ, βKBβ, βMBβ)
- analyze(compressed_obj)[source]ο
Computes and appends binary object size of the compressed object.
- Parameters:
compressed_obj (Any) β compressed object
- class sc2bench.analysis.FileSizeAccumulator(unit='KB', **kwargs)[source]ο
An accumulator to store pre-computed file size in the designated unit.
- Parameters:
unit (str) β unit of data size in bytes (βBβ, βKBβ, βMBβ)
- sc2bench.analysis.get_analyzer(cls_name, **kwargs)[source]ο
Gets an analyzer module.
- Parameters:
cls_name (str) β analyzer class name
kwargs (dict) β kwargs for the analyzer class
- Returns:
analyzer module
- Return type:
BaseAnalyzer or None
- sc2bench.analysis.check_if_analyzable(module)[source]ο
Checks if a module is an instance of AnalyzableModule.
- Parameters:
module (Any) β module
- Returns:
True if the module is an instance of AnalyzableModule. False otherwise
- Return type:
bool
- sc2bench.analysis.analyze_model_size(model, encoder_paths=None, additional_rest_paths=None, ignores_dtype_error=True)[source]ο
Approximates numbers of bits used for parameters of the whole model, encoder, and the rest of the model.
- Parameters:
model (nn.Module) β model
encoder_paths (list[str] or None) β list of module paths for the model to be considered as part of encoderβs parameters
additional_rest_paths (list[str] or None) β list of additional rest module paths whose parameters should be shared with encoder e.g., module path of entropy bottleneck in the model if applied
ignores_dtype_error (bool) β if False, raise an error when any unexpected dtypes are found
- Returns:
model size (sum of param x num_bits) with three keys: model (whole model), encoder, and the rest
- Return type:
dict