Skip to content

Commit

Permalink
better assert
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidrains committed Nov 20, 2023
1 parent a75b111 commit bf716ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions magvit2_pytorch/magvit2_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ def __init__(
),
residual_conv_kernel_size = 3,
num_codebooks = 1,
codebook_size = 8192,
codebook_size: Optional[int] = None,
channels = 3,
init_dim = 64,
max_dim = float('inf'),
Expand All @@ -1035,7 +1035,7 @@ def __init__(
quantizer_aux_loss_weight = 1.,
lfq_activation = nn.Identity(),
use_fsq = False,
fsq_levels: List[int] = [8, 5, 5, 5],
fsq_levels: Optional[List[int]] = None,
attn_dim_head = 32,
attn_heads = 8,
attn_dropout = 0.,
Expand Down Expand Up @@ -1320,6 +1320,8 @@ def __init__(
self.use_fsq = use_fsq

if not use_fsq:
assert exists(codebook_size) and not exists(fsq_levels), 'if use_fsq is set to False, `codebook_size` must be set (and not `fsq_levels`)'

# lookup free quantizer(s) - multiple codebooks is possible
# each codebook will get its own entropy regularization

Expand All @@ -1333,6 +1335,8 @@ def __init__(
)

else:
assert not exists(codebook_size) and exists(fsq_levels), 'if use_fsq is set to True, `fsq_levels` must be set (and not `codebook_size`). the effective codebook size is the cumulative product of all the FSQ levels'

self.quantizers = FSQ(
fsq_levels,
dim = dim,
Expand Down
2 changes: 1 addition & 1 deletion magvit2_pytorch/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.31'
__version__ = '0.1.32'

0 comments on commit bf716ef

Please sign in to comment.