singular values
get_conv_sv(layer, n_iter, agg_groups=True, return_stab_rank=True, device=None, detach=True, imsize=None)
¶
Computes Lipschitz constant (and optional 'stability rank') of a convolution layer. This use the layer paramaters to decide the correct function to call depending the the padding mode, the shape of the kernel and the stride. Under the hood it uses the methods described in [1] and [2].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer
|
Module
|
Convolutional layer to compute the Lipschitz constant for. It must have a weight attribute. This function is expected to work only for layer in this library as striding is handled using the fact that our layers uses two subkernels in this situation. |
required |
n_iter
|
int
|
Number of iterations for the Delattre algorithm. |
required |
agg_groups
|
bool
|
If True, the Lipschitz constant is computed for the entire layer. If False, the Lipschitz constant is computed for each group separately. Default is True. |
True
|
return_stab_rank
|
bool
|
If True, the function also returns the 'stability rank' of the layer (normalized to be a fraction of the full rank). When agg_groups = True the average stable rank over groups is returned. Default is True. |
True
|
device
|
device
|
Device to use for the computation. Default is None. |
None
|
detach
|
bool
|
If True, the result is detached from the computation graph. Default is True. |
True
|
imsize
|
int
|
Size of the input image. Required for circular padding. Default is None. |
None
|
Returns:
Type | Description |
---|---|
float or tuple: Lipschitz constant of the layer. If return_stab_rank is True, the function returns a tuple |
References
- [1] Delattre, B., Barthélemy, Q., Araujo, A., & Allauzen, A. (2023, July). Efficient bound of Lipschitz constant for convolutional layers by gram iteration. In International Conference on Machine Learning (pp. 7513-7532). PMLR. https://arxiv.org/abs/2305.16173
- [2] Delattre, B., Barthélemy, Q., & Allauzen, A. (2024). Spectral Norm of Convolutional Layers with Circular and Zero Paddings. https://arxiv.org/abs/2402.00240
Source code in orthogonium\layers\conv\singular_values\get_sv.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|