1- from typing import Dict , List , Optional
1+ from __future__ import annotations
22
33from compressed_tensors import CompressionFormat , SparsityCompressionConfig
44from compressed_tensors .config import SparsityStructure
@@ -30,7 +30,7 @@ class SparsityConfigMetadata:
3030
3131 @staticmethod
3232 def infer_global_sparsity (
33- model : Module , state_dict : Optional [ Dict [ str , Tensor ]] = None
33+ model : Module , state_dict : dict [ str , Tensor ] | None = None
3434 ) -> float :
3535 """
3636 Calculates the global percentage of sparse zero weights in the model
@@ -47,12 +47,12 @@ def infer_global_sparsity(
4747
4848 @staticmethod
4949 def infer_sparsity_structure (
50- model : Optional [ Module ] = None , check_only_modifiers : Optional [ bool ] = False
50+ model : Module | None = None , check_only_modifiers : bool | None = False
5151 ) -> str :
5252 """
5353 Determines what sparsity structure, if any, was applied.
5454
55- First, there is an attempt to dedue the sparsity structure
55+ First, there is an attempt to deduce the sparsity structure
5656 from the currently active sparse session.
5757
5858 If that fails, the sparsity structure is inferred from the
@@ -83,12 +83,12 @@ def infer_sparsity_structure(
8383 @staticmethod
8484 def from_pretrained (
8585 model : Module ,
86- state_dict : Optional [ Dict [ str , Tensor ]] = None ,
86+ state_dict : dict [ str , Tensor ] | None = None ,
8787 compress : bool = False ,
88- quantization_format : Optional [ CompressionFormat ] = None ,
88+ quantization_format : CompressionFormat | None = None ,
8989 disable_sparse_compression : bool = False ,
90- sparsity_structure : Optional [ str ] = None ,
91- ) -> Optional [ " SparsityCompressionConfig" ] :
90+ sparsity_structure : str | None = None ,
91+ ) -> SparsityCompressionConfig | None :
9292 """
9393 Determines compression type and informational parameters for a given model
9494
@@ -155,7 +155,7 @@ def from_pretrained(
155155 def fill_config_details (
156156 config : SparsityCompressionConfig ,
157157 model : Module ,
158- state_dict : Optional [ Dict [ str , Tensor ]] = None ,
158+ state_dict : dict [ str , Tensor ] | None = None ,
159159 ):
160160 """
161161 Fills in informational sparsity parameters from a given model
@@ -173,7 +173,7 @@ def fill_config_details(
173173 @staticmethod
174174 def is_sparse24_bitmask_supported (
175175 model : Module ,
176- sparsity_structure : Optional [ str ] = None ,
176+ sparsity_structure : str | None = None ,
177177 ) -> bool :
178178 """
179179 Determines if sparse 24 bitmask sparse compressor is supported for a given model
@@ -202,7 +202,7 @@ def is_sparse24_bitmask_supported(
202202
203203 # when model is quantized, and has 2:4 sparsity
204204
205- supported_scheme_types : List [str ] = [
205+ supported_scheme_types : list [str ] = [
206206 QuantizationType .INT .value ,
207207 QuantizationType .FLOAT .value ,
208208 ]
0 commit comments