nncf/experimental/torch/nas/bootstrapNAS/elasticity/elastic_width.py
def mask_to_width(mask: NNCFTensor) -> Optional[int]:
        """
        Decodes mask to a single integer. We assume that mask was constructed in a way that first N values are equal
        to 1, and the rest values are 0. The N encodes width value.

        :param mask: tensor with 1 and 0 values.
        :return: width value
        """
        result = None
        if mask is not None:
            actual_mask = mask.tensor
            mask_len = sum(actual_mask.size())
            width = int(sum(actual_mask))
            device = actual_mask.device
            ref_mask = ElasticWidthHandler._width_to_mask(width, mask_len, device).tensor
            assert torch.equal(ref_mask, actual_mask), \
                f'Invalid mask {actual_mask}: the first {width} values must be ones, the rest - zeros.'
            result = width
        return result

        Decodes mask to a single integer. We assume that mask was constructed in a way that first N values are equal
        to 1, and the rest values are 0. The N encodes width value.

        :param mask: tensor with 1 and 0 values.
        :return: width value
        
Decodes mask to a single integer. We assume that mask was constructed in a way that first N values are equal
to 1, and the rest values are 0. The N encodes width value.
Decodes mask to a single integer . We assume that mask was constructed in a way that first N values are equal to 1 and the rest values are 0 . The N encodes width value .
def mask_to_width(mask: NNCFTensor) -> Optional[int]:
        result = None
        if mask is not None:
            actual_mask = mask.tensor
            mask_len = sum(actual_mask.size())
            width = int(sum(actual_mask))
            device = actual_mask.device
            ref_mask = ElasticWidthHandler._width_to_mask(width, mask_len, device).tensor
            assert torch.equal(ref_mask, actual_mask), \
                f'Invalid mask {actual_mask}: the first {width} values must be ones, the rest - zeros.'
            result = width
        return result
def mask_to_width ( mask : NNCFTensor ) -> Optional [ int ] : result = None if mask is not None : actual_mask = mask . tensor mask_len = sum ( actual_mask . size ( ) ) width = int ( sum ( actual_mask ) ) device = actual_mask . device ref_mask = ElasticWidthHandler . _width_to_mask ( width , mask_len , device ) . tensor assert torch . equal ( ref_mask , actual_mask ) , f'Invalid mask {actual_mask}: the first {width} values must be ones, the rest - zeros.' result = width return result
Decodes mask to a single integer.
Decodes mask to a single integer .
"""
        Decodes mask to a single integer. We assume that mask was constructed in a way that first N values are equal
        to 1, and the rest values are 0. The N encodes width value.

        :param mask: tensor with 1 and 0 values.
        :return: width value
        """
None
mask
NNCFTensor
tensor with 1 and 0 values.
tensor with 1 and 0 values .