text stringlengths 1 93.6k |
|---|
cross_attn_mask), (labels, loss_mask)
|
def forward_step(data_iterator, model):
|
"""Forward step."""
|
args = get_args()
|
timers = get_timers()
|
# Get the batch.
|
timers('batch generator').start()
|
(enc_token_ids, enc_pos_ids, enc_attn_mask,
|
dec_token_ids, dec_pos_ids, dec_attn_mask,
|
cross_attn_mask), (labels, loss_mask) = get_batch(data_iterator)
|
timers('batch generator').stop()
|
# Forward model.
|
losses = model(enc_token_ids, enc_pos_ids, enc_attn_mask,
|
dec_token_ids, dec_pos_ids, dec_attn_mask, cross_attn_mask,
|
labels=labels)
|
loss_mask = loss_mask.view(-1)
|
loss = torch.sum(losses.view(-1) * loss_mask) / loss_mask.sum()
|
# Reduce loss for logging.
|
reduced_loss = reduce_losses([loss])
|
return loss, {'lm loss': reduced_loss[0]}
|
def train_valid_test_datasets_provider(train_val_test_num_samples):
|
"""Build train, valid, and test datasets."""
|
args = get_args()
|
tokenizer = get_tokenizer()
|
print_rank_0('> building train, validation, and test datasets '
|
'for Enc-Dec ...')
|
train_ds, valid_ds, test_ds = build_train_valid_test_datasets(
|
tokenizer=tokenizer,
|
data_prefix=args.data_path,
|
data_impl=args.data_impl,
|
splits_string=args.split,
|
train_valid_test_num_samples=train_val_test_num_samples,
|
enc_seq_length=args.enc_seq_length,
|
dec_seq_length=args.dec_seq_length,
|
seed=args.seed,
|
skip_warmup=(not args.mmap_warmup))
|
print_rank_0("> finished creating Enc-Dec datasets ...")
|
return train_ds, valid_ds, test_ds
|
if __name__ == "__main__":
|
pretrain(train_valid_test_datasets_provider, model_provider, forward_step,
|
args_defaults={'tokenizer_type': 'T5Tokenizer'})
|
# <FILESEP>
|
import os
|
import gc
|
import numpy as np
|
import torch
|
from PIL import Image
|
from torch.utils.data import Dataset
|
import legacy
|
import dnnlib
|
from model import Generator_feat
|
from util import bilinear_interp_sampling
|
def img_np2pt(img):
|
return torch.FloatTensor(np.array(img) / 255)
|
def sample_fpyr(G, latent):
|
with torch.no_grad():
|
fpyr, _ = G.synthesis(latent, noise_mode='const')
|
return [m.cpu() for m in fpyr]
|
def id_replace(s):
|
s = s.replace('env1', 'env0')
|
s = s.replace('env2', 'env0')
|
s = s.replace('env3', 'env0')
|
s = s.replace('env4', 'env0')
|
s = s.replace('env5', 'env0')
|
return s
|
class StyleGANNormalDataset(Dataset):
|
def __init__(self, latent_path, normal_path, weight_path, weight_name, mask_path=None):
|
self.latent_path = latent_path
|
self.normal_path = normal_path
|
self.weight_path = weight_path
|
self.weight_name = weight_name
|
self.mask_path = mask_path
|
self.device = torch.device('cuda:0')
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.