Skip to content

Commit 31764e2

Browse files
Support projection_lcl_residual_blocks and lcl_residual+mlp projection type in adversarial disentanglement module.
1 parent b6ae88f commit 31764e2

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/eir/setup/schema_modules/adversarial_schemas.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ class AdversarialConfig:
4949
:param projection_type:
5050
Type of projection layer to use before the adversarial discriminator.
5151
52+
:param projection_lcl_residual_blocks:
53+
When ``projection_type='lcl+mlp_residual'``, use progressive LCL residual
54+
blocks to reduce dimensionality before the final MLP residual block,
55+
instead of a single LCL projection. Useful for very high-dimensional
56+
embeddings where a dense MLP would blow up in parameters.
57+
5258
:param embedding_cache_target:
5359
Whether to cache 'input' or 'output' of the embedding layer.
5460
Default 'output' caches the layer's output activations.
@@ -71,8 +77,14 @@ class AdversarialConfig:
7177
dropout_p: float = 0.1
7278
stochastic_depth_p: float = 0.0
7379
projection_type: Literal[
74-
"linear", "lcl", "lcl_residual", "mlp_residual", "grouped_linear"
80+
"linear",
81+
"lcl",
82+
"lcl_residual",
83+
"mlp_residual",
84+
"lcl+mlp_residual",
85+
"grouped_linear",
7586
] = "linear"
87+
projection_lcl_residual_blocks: bool = True
7688
embedding_cache_target: Literal["input", "output"] = "output"
7789
target_cache_target: Literal["input", "output"] = "output"
7890

src/eir/train_utils/adversarial.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ def __init__(
4343
dropout_p: float = 0.1,
4444
stochastic_depth_p: float = 0.0,
4545
projection_type: Literal[
46-
"linear", "lcl", "lcl_residual", "mlp_residual", "grouped_linear"
46+
"linear",
47+
"lcl",
48+
"lcl_residual",
49+
"mlp_residual",
50+
"lcl+mlp_residual",
51+
"grouped_linear",
4752
] = "linear",
53+
projection_lcl_residual_blocks: bool = True,
4854
):
4955
super().__init__()
5056
self.embedding_dim = embedding_dim
@@ -53,6 +59,7 @@ def __init__(
5359
self.layers = layers if layers is not None else [2]
5460
self.dropout_p = dropout_p
5561
self.projection_type = projection_type
62+
self.projection_lcl_residual_blocks = projection_lcl_residual_blocks
5663

5764
from_shape = torch.Size([embedding_dim])
5865
to_shape = torch.Size([fc_dim])
@@ -62,6 +69,7 @@ def __init__(
6269
to_shape_no_batch=to_shape,
6370
cache_fusion_type="sum",
6471
projection_type=projection_type,
72+
projection_lcl_residual_blocks=projection_lcl_residual_blocks,
6573
)
6674

6775
mlp_blocks = []
@@ -143,6 +151,9 @@ def hook_add_adversarial_losses(
143151
dropout_p=adv_config.dropout_p,
144152
stochastic_depth_p=adv_config.stochastic_depth_p,
145153
projection_type=adv_config.projection_type,
154+
projection_lcl_residual_blocks=(
155+
adv_config.projection_lcl_residual_blocks
156+
),
146157
)
147158
module = module.to(device=device)
148159
adversarial_modules[adv_config.name] = module

0 commit comments

Comments
 (0)