<jupyter_start><jupyter_text>Finding mean for truncation trick<jupyter_code>n_sample = 1
sample_z = torch.randn(n_sample, args.latent, device=device)
converted_full = convert_to_coord_format(sample_z.size(0), args.coords_size, args.coords_size, device,
                                         integer_values=args.coords_integer_values)

latents = []
samples = []
with torch.no_grad():
    for _ in range(100):
        sample_z = torch.randn(n_sample, args.latent, device=device)
        sample, latent = g_ema(converted_full, [sample_z], return_latents=True)
        latents.append(latent.cpu())
        samples.append(sample.cpu())

samples = torch.cat(samples, 0)
latents = torch.cat(latents, 0)

truncation_latent = latents.mean(0).cuda()

print('truncation_latent', truncation_latent.shape)
assert len(truncation_latent.shape)==1 and truncation_latent.size(0) == 512, 'smt wrong'<jupyter_output><empty_output><jupyter_text>Sampling with truncation trick<jupyter_code>n_sample = 4
sample_z = torch.randn(n_sample, args.latent, device=device)
converted_full = convert_to_coord_format(sample_z.size(0), args.coords_size, args.coords_size, device,
                                         integer_values=args.coords_integer_values)

with torch.no_grad():
    style = g_ema.style(sample_z)
    sample, _ = g_ema(converted_full, [style], 
                      truncation=0.6,
                      truncation_latent=truncation_latent,
                      input_is_latent=True,)
    
im = get_image(sample,                        
                nrow=int(n_sample ** 0.5),
                normalize=True,
                range=(-1, 1),)

im<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11004784688995216, 'fraction_numerical': 0.012559808612440191, 'mean_word_length': 3.0606796116504853, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '190130', 'license': 'MIT', 'n_tokens_mistral': 577, 'n_tokens_neox': 546, 'n_words': 83, 'path': 'notebook.ipynb', 'repo_name': 'Ugness/CIPS_SR', 'size': '1672'}