code
stringlengths
17
6.64M
class DiagonalGaussianDensity(Density): def __init__(self, mean, stddev, num_fixed_samples=0): super().__init__() assert (mean.shape == stddev.shape) self.register_buffer('mean', mean) self.register_buffer('stddev', stddev) if (num_fixed_samples > 0): self.regi...
class MarginalDensity(Density): def __init__(self, prior: Density, likelihood: ConditionalDensity, approx_posterior: ConditionalDensity): super().__init__() self.prior = prior self.likelihood = likelihood self.approx_posterior = approx_posterior def p_parameters(self): ...
class SplitDensity(Density): def __init__(self, density_1, density_2, dim): super().__init__() self.density_1 = density_1 self.density_2 = density_2 self.dim = dim def _elbo(self, x, detach_q_params, detach_q_samples): (x1, x2) = torch.chunk(x, chunks=2, dim=self.dim)...
class WrapperDensity(Density): def __init__(self, density): super().__init__() self.density = density def p_parameters(self): return self.density.p_parameters() def q_parameters(self): return self.density.q_parameters() def elbo(self, x, num_importance_samples, deta...
class DequantizationDensity(WrapperDensity): def elbo(self, x, num_importance_samples, detach_q_params, detach_q_samples): return super().elbo(x.add_(torch.rand_like(x)), num_importance_samples=num_importance_samples, detach_q_params=detach_q_params, detach_q_samples=detach_q_samples)
class BinarizationDensity(WrapperDensity): def __init__(self, density, scale): super().__init__(density) self.scale = scale def elbo(self, x, num_importance_samples, detach_q_params, detach_q_samples): bernoulli = dist.bernoulli.Bernoulli(probs=(x / self.scale)) return super(...
class PassthroughBeforeEvalDensity(WrapperDensity): def __init__(self, density, x): super().__init__(density) self.register_buffer('x', x) def train(self, train_mode=True): if (not train_mode): self.training = True with torch.no_grad(): self.el...
class ConstantNetwork(nn.Module): def __init__(self, value, fixed): super().__init__() if fixed: self.register_buffer('value', value) else: self.value = nn.Parameter(value) def forward(self, inputs): return self.value.expand(inputs.shape[0], *self.valu...
class ResidualBlock(nn.Module): def __init__(self, num_channels): super().__init__() self.bn1 = nn.BatchNorm2d(num_channels) self.conv1 = self._get_conv3x3(num_channels) self.bn2 = nn.BatchNorm2d(num_channels) self.conv2 = self._get_conv3x3(num_channels) def forward(s...
class ScaledTanh2dModule(nn.Module): def __init__(self, module, num_channels): super().__init__() self.module = module self.weights = nn.Parameter(torch.ones(num_channels, 1, 1)) self.bias = nn.Parameter(torch.zeros(num_channels, 1, 1)) def forward(self, inputs): out ...
def get_resnet(num_input_channels, hidden_channels, num_output_channels): num_hidden_channels = (hidden_channels[0] if hidden_channels else num_output_channels) layers = [nn.Conv2d(in_channels=num_input_channels, out_channels=num_hidden_channels, kernel_size=3, stride=1, padding=1, bias=False)] for num_hi...
def get_glow_cnn(num_input_channels, num_hidden_channels, num_output_channels, zero_init_output): conv1 = nn.Conv2d(in_channels=num_input_channels, out_channels=num_hidden_channels, kernel_size=3, padding=1, bias=False) bn1 = nn.BatchNorm2d(num_hidden_channels) conv2 = nn.Conv2d(in_channels=num_hidden_cha...
def get_mlp(num_input_channels, hidden_channels, num_output_channels, activation, log_softmax_outputs=False): layers = [] prev_num_hidden_channels = num_input_channels for num_hidden_channels in hidden_channels: layers.append(nn.Linear(prev_num_hidden_channels, num_hidden_channels)) layers...
class MaskedLinear(nn.Module): def __init__(self, input_degrees, output_degrees): super().__init__() assert (len(input_degrees.shape) == len(output_degrees.shape) == 1) num_input_channels = input_degrees.shape[0] num_output_channels = output_degrees.shape[0] self.linear = ...
class AutoregressiveMLP(nn.Module): def __init__(self, num_input_channels, hidden_channels, num_output_heads, activation): super().__init__() self.flat_ar_mlp = self._get_flat_ar_mlp(num_input_channels, hidden_channels, num_output_heads, activation) self.num_input_channels = num_input_cha...
class LipschitzNetwork(nn.Module): _MODULES_TO_UPDATE = (InducedNormConv2d, InducedNormLinear) def __init__(self, layers, max_train_lipschitz_iters, max_eval_lipschitz_iters, lipschitz_tolerance): super().__init__() self.layers = layers self.net = nn.Sequential(*layers) self.m...
def get_lipschitz_mlp(num_input_channels, hidden_channels, num_output_channels, lipschitz_constant, max_train_lipschitz_iters, max_eval_lipschitz_iters, lipschitz_tolerance): layers = [] prev_num_channels = num_input_channels for (i, num_channels) in enumerate((hidden_channels + [num_output_channels])): ...
def _get_lipschitz_linear_layer(num_input_channels, num_output_channels, lipschitz_constant, max_lipschitz_iters, lipschitz_tolerance, zero_init): return InducedNormLinear(in_features=num_input_channels, out_features=num_output_channels, coeff=lipschitz_constant, domain=2, codomain=2, n_iterations=max_lipschitz_i...
def get_lipschitz_cnn(input_shape, num_hidden_channels, num_output_channels, lipschitz_constant, max_train_lipschitz_iters, max_eval_lipschitz_iters, lipschitz_tolerance): assert (len(input_shape) == 3) num_input_channels = input_shape[0] conv1 = _get_lipschitz_conv_layer(num_input_channels=num_input_chan...
def _get_lipschitz_conv_layer(num_input_channels, num_output_channels, kernel_size, padding, lipschitz_constant, max_lipschitz_iters, lipschitz_tolerance): assert ((max_lipschitz_iters is not None) or (lipschitz_tolerance is not None)) return InducedNormConv2d(in_channels=num_input_channels, out_channels=num_...
def get_density(schema, x_train): x_shape = x_train.shape[1:] if (schema[0]['type'] == 'passthrough-before-eval'): num_points = schema[0]['num_passthrough_data_points'] x_idxs = torch.randperm(x_train.shape[0])[:num_points] return PassthroughBeforeEvalDensity(density=get_density_recurs...
def get_density_recursive(schema, x_shape): if (not schema): return get_standard_gaussian_density(x_shape=x_shape) layer_config = schema[0] schema_tail = schema[1:] if (layer_config['type'] == 'dequantization'): return DequantizationDensity(density=get_density_recursive(schema=schema_t...
def get_marginal_density(layer_config, schema_tail, x_shape): (likelihood, z_shape) = get_likelihood(layer_config, schema_tail, x_shape) prior = get_density_recursive(schema_tail, z_shape) approx_posterior = DiagonalGaussianConditionalDensity(coupler=get_coupler(input_shape=x_shape, num_channels_per_outpu...
def get_likelihood(layer_config, schema_tail, x_shape): z_shape = (layer_config['num_z_channels'], *x_shape[1:]) if (layer_config['type'] == 'gaussian-likelihood'): likelihood = DiagonalGaussianConditionalDensity(coupler=get_coupler(input_shape=z_shape, num_channels_per_output=x_shape[0], config=layer...
def get_bijection_density(layer_config, schema_tail, x_shape): bijection = get_bijection(layer_config=layer_config, x_shape=x_shape) prior = get_density_recursive(schema=schema_tail, x_shape=bijection.z_shape) if (layer_config.get('num_u_channels', 0) == 0): return FlowDensity(bijection=bijection,...
def get_uniform_density(x_shape): return FlowDensity(bijection=LogitBijection(x_shape=x_shape).inverse(), prior=UniformDensity(x_shape))
def get_standard_gaussian_density(x_shape): return DiagonalGaussianDensity(mean=torch.zeros(x_shape), stddev=torch.ones(x_shape), num_fixed_samples=64)
def get_bijection(layer_config, x_shape): if (layer_config['type'] == 'acl'): return get_acl_bijection(config=layer_config, x_shape=x_shape) elif (layer_config['type'] == 'squeeze'): return Squeeze2dBijection(x_shape=x_shape, factor=layer_config['factor']) elif (layer_config['type'] == 'lo...
def get_acl_bijection(config, x_shape): num_x_channels = x_shape[0] num_u_channels = config['num_u_channels'] if (config['mask_type'] == 'checkerboard'): return Checkerboard2dAffineCouplingBijection(x_shape=x_shape, coupler=get_coupler(input_shape=((num_x_channels + num_u_channels), *x_shape[1:]),...
def get_conditional_density(num_u_channels, coupler_config, x_shape): return DiagonalGaussianConditionalDensity(coupler=get_coupler(input_shape=x_shape, num_channels_per_output=num_u_channels, config=coupler_config))
def get_coupler(input_shape, num_channels_per_output, config): if config['independent_nets']: return get_coupler_with_independent_nets(input_shape=input_shape, num_channels_per_output=num_channels_per_output, shift_net_config=config['shift_net'], log_scale_net_config=config['log_scale_net']) else: ...
def get_coupler_with_shared_net(input_shape, num_channels_per_output, net_config): return ChunkedSharedCoupler(shift_log_scale_net=get_net(input_shape=input_shape, num_output_channels=(2 * num_channels_per_output), net_config=net_config))
def get_coupler_with_independent_nets(input_shape, num_channels_per_output, shift_net_config, log_scale_net_config): return IndependentCoupler(shift_net=get_net(input_shape=input_shape, num_output_channels=num_channels_per_output, net_config=shift_net_config), log_scale_net=get_net(input_shape=input_shape, num_ou...
def get_net(input_shape, num_output_channels, net_config): num_input_channels = input_shape[0] if (net_config['type'] == 'mlp'): assert (len(input_shape) == 1) return get_mlp(num_input_channels=num_input_channels, hidden_channels=net_config['hidden_channels'], num_output_channels=num_output_ch...
def get_activation(name): if (name == 'tanh'): return nn.Tanh elif (name == 'relu'): return nn.ReLU else: assert False, f'Invalid activation {name}'
def get_lipschitz_net(input_shape, num_output_channels, config): if (config['type'] == 'cnn'): return get_lipschitz_cnn(input_shape=input_shape, num_hidden_channels=config['num_hidden_channels'], num_output_channels=num_output_channels, lipschitz_constant=config['lipschitz_constant'], max_train_lipschitz_...
class AverageMetric(Metric): _required_output_keys = ['metrics'] def reset(self): self._sums = Counter() self._num_examples = Counter() def update(self, output): (metrics,) = output for (k, v) in metrics.items(): self._sums[k] += torch.sum(v) self....
class Trainer(): _STEPS_PER_LOSS_WRITE = 10 _STEPS_PER_GRAD_WRITE = 10 _STEPS_PER_LR_WRITE = 10 def __init__(self, module, device, train_metrics, train_loader, opts, lr_schedulers, max_epochs, max_grad_norm, test_metrics, test_loader, epochs_per_test, early_stopping, valid_loss, valid_loader, max_bad...
class Tee(): def __init__(self, primary_file, secondary_file): self.primary_file = primary_file self.secondary_file = secondary_file self.encoding = self.primary_file.encoding def isatty(self): return self.primary_file.isatty() def fileno(self): return self.prima...
class Writer(): _STDOUT = sys.stdout _STDERR = sys.stderr def __init__(self, logdir, make_subdir, tag_group): if make_subdir: os.makedirs(logdir, exist_ok=True) timestamp = f"{datetime.datetime.now().strftime('%b%d_%H-%M-%S')}" logdir = os.path.join(logdir, tim...
class DummyWriter(Writer): def __init__(self, logdir): self._logdir = logdir def write_scalar(self, tag, scalar_value, global_step=None): pass def write_image(self, tag, img_tensor, global_step=None): pass def write_figure(self, tag, figure, global_step=None): pass ...
def get_config_group(dataset): for (group, group_data) in CONFIG_GROUPS.items(): if (dataset in group_data['datasets']): return group assert False, f"Dataset `{dataset}' not found"
def get_datasets(): result = [] for items in CONFIG_GROUPS.values(): result += items['datasets'] return result
def get_models(): result = [] for items in CONFIG_GROUPS.values(): result += list(items['model_configs']) return result
def get_base_config(dataset, use_baseline): return CONFIG_GROUPS[get_config_group(dataset)]['base_config'](dataset, use_baseline)
def get_model_config(dataset, model, use_baseline): group = CONFIG_GROUPS[get_config_group(dataset)] return group['model_configs'][model](dataset, model, use_baseline)
def get_config(dataset, model, use_baseline): config = {**get_base_config(dataset, use_baseline), **get_model_config(dataset, model, use_baseline)} if use_baseline: for prefix in ['s', 't', 'st']: config.pop(f'{prefix}_nets', None) for prefix in ['p', 'q']: for suffix i...
def expand_grid_generator(config): if (not config): (yield {}) return items = list(config.items()) (first_key, first_val) = items[0] rest = dict(items[1:]) for config in expand_grid_generator(rest): if isinstance(first_val, GridParams): for val in first_val: ...
def expand_grid(config): return list(expand_grid_generator(config))
def group(group, datasets): global CURRENT_CONFIG_GROUP assert (group not in CONFIG_GROUPS), f"Already exists group `{group}'" for dataset in datasets: for group_data in CONFIG_GROUPS.values(): assert (dataset not in group_data['datasets']), f"Dataset `{dataset}' already registered in ...
def base(f): assert (CONFIG_GROUPS[CURRENT_CONFIG_GROUP]['base_config'] is None), 'Already exists a base config' CONFIG_GROUPS[CURRENT_CONFIG_GROUP]['base_config'] = f return f
def provides(*models): def store_and_return(f): assert (CURRENT_CONFIG_GROUP is not None), 'Must register a config group first' for m in models: assert (m not in CONFIG_GROUPS[CURRENT_CONFIG_GROUP]['model_configs']), f"Already exists model `{m}' in group `{CURRENT_CONFIG_GROUP}'" ...
class GridParams(): def __init__(self, *values): self.values = values def __iter__(self): return iter(self.values) def __repr__(self): return f"{self.__class__.__name__}({', '.join((str(v) for v in self.values))})"
@base def config(dataset, use_baseline): assert (not use_baseline), 'Cannot use baseline model for this config' return {'pure_cond_affine': False, 'dequantize': False, 'batch_norm': False, 'act_norm': False, 'max_epochs': 2000, 'max_grad_norm': None, 'early_stopping': True, 'max_bad_valid_epochs': 50, 'train_...
@provides('vae') def vae(dataset, model, use_baseline): return {'schema_type': 'gaussian-vae', 'use_cond_affine': False, 'num_z_channels': 1, 'p_mu_nets': [], 'p_sigma_nets': 'learned-constant', 'q_nets': [10, 10]}
@base def config(dataset, use_baseline): return {'num_u_channels': 1, 'use_cond_affine': True, 'pure_cond_affine': False, 'dequantize': True, 'act_norm': False, 'batch_norm': True, 'batch_norm_apply_affine': use_baseline, 'batch_norm_use_running_averages': True, 'batch_norm_momentum': 0.1, 'lr_schedule': 'none', ...
@provides('bernoulli-vae') def bernoulli_vae(dataset, model, use_baseline): assert (not use_baseline), 'Cannot use baseline model for this config' return {'schema_type': 'bernoulli-vae', 'dequantize': False, 'binarize_scale': 255, 'logit_net': ([200] * 2), 'q_nets': ([200] * 2), 'num_z_channels': 50, 'train_b...
@provides('realnvp') def realnvp(dataset, model, use_baseline): config = {'schema_type': 'multiscale-realnvp', 'g_hidden_channels': (([64] * 8) if use_baseline else ([64] * 4)), 'st_nets': ([8] * 2), 'p_nets': ([64] * 2), 'q_nets': ([64] * 2), 'train_batch_size': 100, 'valid_batch_size': 500, 'test_batch_size': 5...
@provides('glow') def glow(dataset, model, use_baseline): assert (dataset in ['cifar10', 'svhn']), 'Currently only implemented for images of size 3x32x32' warnings.warn('Glow may quickly diverge for certain random seeds - if this happens just retry. This behaviour appears to be consistent with that in https:/...
@provides('resflow-small') def resflow(dataset, model, use_baseline): logit_tf_lambda = {'mnist': 1e-06, 'fashion-mnist': 1e-06, 'cifar10': 0.05, 'svhn': 0.05}[dataset] return {'schema_type': 'multiscale-resflow', 'train_batch_size': 64, 'valid_batch_size': 128, 'test_batch_size': 128, 'epochs_per_test': 5, '...
def get_schema(config): schema = get_base_schema(config=config) if config['pure_cond_affine']: assert config['use_cond_affine'] schema = remove_non_normalise_layers(schema=schema) if config['use_cond_affine']: assert (config['num_u_channels'] > 0) schema = add_cond_affine_b...
def get_preproc_schema(config): if config['dequantize']: schema = [{'type': 'dequantization'}] else: schema = [] if (config.get('binarize_scale') is not None): schema += get_binarize_schema(config['binarize_scale']) if ((config.get('logit_tf_lambda') is not None) and (config.ge...
def get_base_schema(config): ty = config['schema_type'] if (ty == 'multiscale-realnvp'): return get_multiscale_realnvp_schema(coupler_hidden_channels=config['g_hidden_channels']) elif (ty == 'flat-realnvp'): return get_flat_realnvp_schema(config=config) elif (ty == 'maf'): retu...
def remove_non_normalise_layers(schema): return [layer for layer in schema if (layer['type'] == 'normalise')]
def remove_normalise_layers(schema): return [layer for layer in schema if (layer['type'] != 'normalise')]
def replace_normalise_with_batch_norm(schema, config): if config['batch_norm_use_running_averages']: new_schema = [] momentum = config['batch_norm_momentum'] else: new_schema = [{'type': 'passthrough-before-eval', 'num_passthrough_data_points': 100000}] momentum = 1.0 apply...
def replace_normalise_with_act_norm(schema): new_schema = [] for layer in schema: if (layer['type'] == 'normalise'): new_schema.append({'type': 'act-norm'}) else: new_schema.append(layer) return new_schema
def add_cond_affine_before_each_normalise(schema, config): new_schema = [] flattened = False for layer in schema: if (layer['type'] == 'flatten'): flattened = True elif (layer['type'] == 'normalise'): new_schema.append(get_cond_affine_layer(config, flattened)) ...
def apply_pq_coupler_config_settings(schema, config): new_schema = [] flattened = False for layer in schema: if (layer['type'] == 'flatten'): flattened = True if (layer.get('num_u_channels', 0) > 0): layer = {**layer, 'p_coupler': get_p_coupler_config(config, flatte...
def get_binarize_schema(scale): return [{'type': 'binarize', 'scale': scale}]
def get_logit_tf_schema(lam, scale): return [{'type': 'scalar-mult', 'value': ((1 - (2 * lam)) / scale)}, {'type': 'scalar-add', 'value': lam}, {'type': 'logit'}]
def get_centering_tf_schema(scale): return [{'type': 'scalar-mult', 'value': (1 / scale)}, {'type': 'scalar-add', 'value': (- 0.5)}]
def get_cond_affine_layer(config, flattened): return {'type': 'cond-affine', 'num_u_channels': config['num_u_channels'], 'st_coupler': get_st_coupler_config(config, flattened)}
def get_st_coupler_config(config, flattened): return get_coupler_config('t', 's', 'st', config, flattened)
def get_p_coupler_config(config, flattened): return get_coupler_config('p_mu', 'p_sigma', 'p', config, flattened)
def get_q_coupler_config(config, flattened): return get_coupler_config('q_mu', 'q_sigma', 'q', config, flattened)
def get_coupler_config(shift_prefix, log_scale_prefix, shift_log_scale_prefix, config, flattened): shift_key = f'{shift_prefix}_nets' log_scale_key = f'{log_scale_prefix}_nets' shift_log_scale_key = f'{shift_log_scale_prefix}_nets' if ((shift_key in config) and (log_scale_key in config)): asse...
def get_coupler_net_config(net_spec, flattened): if (net_spec in ['fixed-constant', 'learned-constant']): return {'type': 'constant', 'value': 0, 'fixed': (net_spec == 'fixed-constant')} elif (net_spec == 'identity'): return {'type': 'identity'} elif isinstance(net_spec, list): if ...
def get_multiscale_realnvp_schema(coupler_hidden_channels): base_schema = [{'type': 'acl', 'mask_type': 'checkerboard', 'reverse_mask': False}, {'type': 'acl', 'mask_type': 'checkerboard', 'reverse_mask': True}, {'type': 'acl', 'mask_type': 'checkerboard', 'reverse_mask': False}, {'type': 'squeeze', 'factor': 2},...
def get_glow_schema(num_scales, num_steps_per_scale, coupler_num_hidden_channels, lu_decomposition): schema = [] for i in range(num_scales): if (i > 0): schema.append({'type': 'split'}) schema.append({'type': 'squeeze', 'factor': 2}) for _ in range(num_steps_per_scale): ...
def get_flat_realnvp_schema(config): result = [{'type': 'flatten'}] if config['coupler_shared_nets']: coupler_config = {'independent_nets': False, 'shift_log_scale_net': {'type': 'mlp', 'hidden_channels': config['coupler_hidden_channels'], 'activation': 'tanh'}} else: coupler_config = {'in...
def get_maf_schema(num_density_layers, hidden_channels): result = [{'type': 'flatten'}] for i in range(num_density_layers): if (i > 0): result.append({'type': 'flip'}) result += [{'type': 'made', 'hidden_channels': hidden_channels, 'activation': 'tanh'}, {'type': 'normalise'}] ...
def get_sos_schema(num_density_layers, hidden_channels, num_polynomials_per_layer, polynomial_degree): result = [{'type': 'flatten'}] for i in range(num_density_layers): if (i > 0): result.append({'type': 'flip'}) result += [{'type': 'sos', 'hidden_channels': hidden_channels, 'acti...
def get_nsf_schema(config): result = [{'type': 'flatten'}] for i in range(config['num_density_layers']): if (('use_linear' in config) and (not config['use_linear'])): result += [{'type': 'rand-channel-perm'}] else: result += [{'type': 'rand-channel-perm'}, {'type': 'lin...
def get_bnaf_schema(num_density_layers, num_hidden_layers, activation, hidden_channels_factor): result = [{'type': 'flatten'}] for i in range(num_density_layers): if (i > 0): result.append({'type': 'flip'}) result += [{'type': 'bnaf', 'num_hidden_layers': num_hidden_layers, 'hidden...
def get_ffjord_schema(num_density_layers, velocity_hidden_channels, numerical_tolerance, num_u_channels): result = [{'type': 'flatten'}] for i in range(num_density_layers): result += [{'type': 'ode', 'hidden_channels': velocity_hidden_channels, 'numerical_tolerance': numerical_tolerance, 'num_u_channe...
def get_planar_schema(config): if (config['num_u_channels'] == 0): layer = {'type': 'planar'} else: layer = {'type': 'cond-planar', 'num_u_channels': config['num_u_channels'], 'cond_hidden_channels': config['cond_hidden_channels'], 'cond_activation': 'tanh'} result = ([layer, {'type': 'nor...
def get_cond_affine_schema(config): return ([{'type': 'flatten'}] + ([{'type': 'normalise'}] * config['num_density_layers']))
def get_affine_schema(config): return ([{'type': 'flatten'}] + ([{'type': 'affine', 'per_channel': False}] * config['num_density_layers']))
def get_flat_resflow_schema(config): result = [{'type': 'flatten'}] for _ in range(config['num_density_layers']): result += [{'type': 'resblock', 'net': {'type': 'mlp', 'hidden_channels': config['hidden_channels']}}, {'type': 'normalise'}] add_lipschitz_config_to_resblocks(result, config) retu...
def get_multiscale_resflow_schema(config): result = [] for (i, num_blocks) in enumerate(config['scales']): if (i == 0): result.append({'type': 'normalise'}) else: result.append({'type': 'squeeze', 'factor': 2}) for j in range(num_blocks): result += [...
def add_lipschitz_config_to_resblocks(schema, config): net_keys_to_copy = ['lipschitz_constant', 'max_train_lipschitz_iters', 'max_test_lipschitz_iters', 'lipschitz_tolerance'] for layer in schema: if (layer['type'] == 'resblock'): for key in net_keys_to_copy: layer['net'][...
def get_bernoulli_vae_schema(config): return [{'type': 'flatten'}, {'type': 'bernoulli-likelihood', 'num_z_channels': config['num_z_channels'], 'logit_net': {'type': 'mlp', 'activation': 'tanh', 'hidden_channels': config['logit_net']}, 'q_coupler': get_q_coupler_config(config, flattened=True)}]
def get_gaussian_vae_schema(config): return [{'type': 'flatten'}, {'type': 'gaussian-likelihood', 'num_z_channels': config['num_z_channels'], 'p_coupler': get_p_coupler_config(config, flattened=True), 'q_coupler': get_q_coupler_config(config, flattened=True)}]
@base def config(dataset, use_baseline): num_u_channels = {'gas': 2, 'power': 2, 'hepmass': 5, 'miniboone': 10, 'bsds300': 15}[dataset] return {'num_u_channels': num_u_channels, 'use_cond_affine': True, 'pure_cond_affine': False, 'dequantize': False, 'act_norm': False, 'batch_norm': True, 'batch_norm_apply_af...
@provides('resflow') def resflow(dataset, model, use_baseline): config = {'schema_type': 'flat-resflow', 'num_density_layers': 10, 'hidden_channels': ([128] * 4), 'lipschitz_constant': 0.9, 'max_train_lipschitz_iters': 5, 'max_test_lipschitz_iters': 200, 'lipschitz_tolerance': None, 'reduce_memory': False, 'act_n...
@provides('cond-affine') def cond_affine(dataset, model, use_baseline): assert (not use_baseline), 'Cannot use baseline model for this config' return {'schema_type': 'cond-affine', 'num_density_layers': 10, 'batch_norm': False, 'st_nets': ([128] * 2), 'p_nets': ([128] * 2), 'q_nets': GridParams(([10] * 2), ([...
@provides('linear-cond-affine-like-resflow') def linear_cond_affine_like_resflow(dataset, model, use_baseline): assert (not use_baseline), 'Cannot use baseline model for this config' assert (dataset != 'bsds300'), 'BSDS300 has not yet been tested' num_u_channels = {'miniboone': 43, 'hepmass': 21, 'gas': 8...
@provides('nonlinear-cond-affine-like-resflow') def nonlinear_cond_affine_like_resflow(dataset, model, use_baseline): assert (not use_baseline), 'Cannot use baseline model for this config' assert (dataset != 'bsds300'), 'BSDS300 has not yet been tested' num_u_channels = {'miniboone': 43, 'hepmass': 21, 'g...
@provides('maf') def maf(dataset, model, use_baseline): if (dataset in ['gas', 'power']): config = {'num_density_layers': 10, 'ar_map_hidden_channels': (([200] * 2) if use_baseline else ([100] * 2)), 'st_nets': ([100] * 2), 'p_nets': ([200] * 2), 'q_nets': ([200] * 2)} elif (dataset in ['hepmass', 'mi...