_base_ = [
    '../../_base_/models/a2mim/deit_small.py',
    '../../_base_/datasets/imagenet100/a2mim_rgb_m_sz192_bs64.py',
    '../../_base_/default_runtime.py',
]

# model settings
model = dict(
    backbone=dict(
        mask_layer=0, mask_token='learnable'),
    neck=dict(
        type='NonLinearMIMNeck',
        decoder_cfg=dict(
            type="ConvNeck",
            in_channels=384, hid_channels=384, out_channels=384,
            num_layers=1, kernel_size=5,
            norm_cfg=dict(type='LN2d'), act_cfg=dict(type='GELU'),  # default
            conv_depthwise=True, with_last_norm=True,
            with_last_dropout=0, with_avg_pool=False, with_residual=False),
    ),
)

# dataset
data = dict(
    # imgs_per_gpu=256, workers_per_gpu=10,
    train=dict(
        feature_mode=None, feature_args=dict(),
        mask_pipeline=[
            dict(type='BlockwiseMaskGenerator',
                input_size=192, mask_patch_size=32, mask_ratio=0.6, model_patch_size=16,
                mask_color='mean', mask_only=False),
        ],
))

# interval for accumulate gradient
update_interval = 2  # total: 4 x bs256 x 2 accumulates = bs2048

# additional hooks
custom_hooks = [
    dict(type='SAVEHook',
        save_interval=124 * 100,  # plot every 50 ep
        iter_per_epoch=124),
]

# optimizer
optimizer = dict(
    type='AdamW',
    lr=2e-4 * 2048 / 512,  # 2e-4 for bs2048
    betas=(0.9, 0.999), weight_decay=0.05, eps=1e-8,
    paramwise_options={
        '(bn|ln|gn)(\d+)?.(weight|bias)': dict(weight_decay=0.),
        'norm': dict(weight_decay=0.),
        'bias': dict(weight_decay=0.),
        'mask_token': dict(weight_decay=0.),
        'pos_embed': dict(weight_decay=0.),
        'cls_token': dict(weight_decay=0.),
        'gamma': dict(weight_decay=0.),
    })

# apex
use_fp16 = False
fp16 = dict(type='mmcv', loss_scale='dynamic')
# optimizer args
optimizer_config = dict(
    update_interval=update_interval,
    grad_clip=dict(max_norm=5.0),
)

# lr scheduler
lr_config = dict(
    policy='StepFixCosineAnnealing',
    by_epoch=False, min_lr=1e-5,
    warmup='linear',
    warmup_iters=10, warmup_by_epoch=True,
    warmup_ratio=1e-6,
)

# runtime settings
runner = dict(type='EpochBasedRunner', max_epochs=800)
