Esempio n. 1
0
    def __init__(self, batch_size=8, steps=100, validate=False):
        super(DiscriminativeLearningRateTask, self).__init__()
        n_total = batch_size * steps
        dataset = XORDataset(n_total)
        if validate:
            n_train = int(n_total * 0.9)
            self.train_loader = DataLoader(
                Subset(dataset, range(n_train)),
                batch_size=batch_size
            )
            self.val_loader = DataLoader(
                Subset(dataset, range(n_train, n_total)),
                batch_size=batch_size
            )
        else:
            self.train_loader = DataLoader(dataset, batch_size=batch_size)
            self.val_loader = None

        self.batch_size = batch_size
        self.model = LinearMLP([8, 4, 1])
        self.optimizer = optim.SGD(
            [
                {"params": self.model.net[0].parameters(), "lr": 1e-3},
                {"params": self.model.net[1].parameters(), "lr": 1e-5},
            ],
            lr=1e-5,
            momentum=0.5,
        )
        self.criterion = nn.MSELoss()
        self.device = torch.device("cuda")
Esempio n. 2
0
    def __init__(self, validate=False):
        super(ExtraXORTask, self).__init__()
        bs, steps = 8, 64
        dataset = ExtraXORDataset(bs * steps, extra_dims=2)
        if validate:
            self.train_loader = DataLoader(Subset(dataset, range(steps - bs)))
            self.val_loader = DataLoader(
                Subset(dataset, range(steps - bs, steps)))
        else:
            self.train_loader = DataLoader(dataset)
            self.val_loader = None

        self.model = LinearMLP([8, 4, 1])
        self.optimizer = optim.SGD(self.model.parameters(), lr=1e-5)
        self.criterion = nn.MSELoss()
        self.device = torch.device("cuda")
Esempio n. 3
0
    def __init__(self, validate=False):
        super(DiscriminativeLearningRateTask, self).__init__()
        bs, steps = 8, 64
        dataset = XORDataset(bs * steps)
        if validate:
            self.train_loader = DataLoader(Subset(dataset, range(steps - bs)))
            self.val_loader = DataLoader(
                Subset(dataset, range(steps - bs, steps)))
        else:
            self.train_loader = DataLoader(dataset)
            self.val_loader = None

        dataset = XORDataset(128)
        self.model = LinearMLP([8, 4, 1])
        self.optimizer = optim.SGD(
            [
                {
                    "params": self.model.net[0].parameters(),
                    "lr": 1e-3
                },
                {
                    "params": self.model.net[1].parameters(),
                    "lr": 1e-5
                },
            ],
            lr=1e-5,
            momentum=0.5,
        )
        self.criterion = nn.MSELoss()
        self.device = torch.device("cuda")
Esempio n. 4
0
    def __init__(self, batch_size=8, steps=100, validate=False):
        super(ExtraXORTask, self).__init__()
        n_total = batch_size * steps
        dataset = ExtraXORDataset(n_total, extra_dims=2)
        if validate:
            n_train = int(n_total * 0.9)
            self.train_loader = DataLoader(Subset(dataset, range(n_train)),
                                           batch_size=batch_size)
            self.val_loader = DataLoader(Subset(dataset,
                                                range(n_train, n_total)),
                                         batch_size=batch_size)
        else:
            self.train_loader = DataLoader(dataset, batch_size=batch_size)
            self.val_loader = None

        self.batch_size = batch_size
        self.model = LinearMLP([8, 4, 1])
        self.optimizer = optim.SGD(self.model.parameters(), lr=1e-5)
        self.criterion = nn.MSELoss()
        self.device = torch.device("cuda")