【问题标题】:big data in pytorch, help for tuning stepspytorch 中的大数据,帮助调整步骤
【发布时间】:2022-01-01 20:18:22
【问题描述】:

我之前已经拆分了我的大数据:

# X_train.shape : 4M samples x 2K features
# X_test.shape : 2M samples x 2K features

我已经准备好了数据加载器

target = torch.tensor(y_train.to_numpy())
features = torch.tensor(X_train.values)
train = data_utils.TensorDataset(features, target)
train_loader = data_utils.DataLoader(train, batch_size=10000, shuffle=True) 

testtarget = torch.tensor(y_test.to_numpy())
testfeatures = torch.tensor(X_test.values)
test = data_utils.TensorDataset(testfeatures, testtarget)
validation_generator = data_utils.DataLoader(test, batch_size=20000, shuffle=True) 

我从在线课程中复制了这个网络示例(不知道其他模型是否更好)

base_elastic_model = ElasticNet()
param_grid = {'alpha':[0.1,1,5,10,50,100],
              'l1_ratio':[.1, .5, .7, .9, .95, .99, 1]}
grid_model = GridSearchCV(estimator=base_elastic_model,
                          param_grid=param_grid,
                          scoring='neg_mean_squared_error',
                          cv=5,
                          verbose=0)

我已经做了这个配件

for epoch in range(1):
    # Training
    cont=0
    total = 0
    correct = 0
    for local_batch, local_labels in train_loader:
        cont+=1
        with torch.set_grad_enabled(True):
            grid_model.fit(local_batch,local_labels)
        with torch.set_grad_enabled(False):
            predicted = grid_model.predict(local_batch)
            total += len(local_labels)
            correct += ((1*(predicted>.5)) == np.array(local_labels)).sum()
        #print stats

    # Validation
    total = 0
    correct = 0

    with torch.set_grad_enabled(False):
        for local_batch, local_labels in validation_generator:
            predicted = grid_model.predict(local_batch)
            total += len(local_labels)
            correct += ((1*(predicted>.5)) == np.array(local_labels)).sum()
            #print stats

也许我的孙子们会有 1 个 epoch 的结果!

我需要一些建议:

  1. 如何/在哪里(在代码中)可以快速使用更少的数据进行第一次调优?
  2. 有人建议在 2022 年取得成果的步骤?
  3. 因为我添加了“with torch.set_grad_enabled(False):”来打印统计信息,我是否需要添加(如已完成)“with torch.set_grad_enabled(True):”?
  4. 我有一个 GPU(无图像时有用吗??)。我有函数“get_device()”。我应该把“.to(get_device())”放在哪里来使用 CUDA?
  5. 我正在学习整理信息,您对我的练习有一般建议吗?

【问题讨论】:

    标签: python pytorch bigdata dataloader


    【解决方案1】:
    1. 通过简单地在一定数量后停止训练循环来缩短训练过程。

      for local_batch, local_labels in train_loader:
      
         cont+=1
         if cont== number_u_want_to_stop:
            break #Breaks out of the for Loop and continues with the rest.
      
    2. 始终使用您的 GPU 进行训练和“推理”,也就是(使用模型进行预测),因为它甚至比最好的 CPU 快 20 多倍。

    3. 不,你不必再让它成为现实。这是使用“with”语法的要点,因此在 with 块中的代码完成后,属性将消失在空气中:)。所以你可以删除这行with a torch.set_grad_enabled(False):

    4. 就像我在第 2 点中所说的,将 GPU 用于所有项目,但请记住,您必须使用至少 4GB 的显卡来训练小模型。

      这里是在 windows 上使用 GPU 的安装 cmd:

      pip3 install torch==1.10.1+cu113 torchvision==0.11.2+cu113 torchaudio===0.10.1+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

      这是适用于 Linux 的一个

      pip3 install torch==1.10.1+cu113 torchvision==0.11.2+cu113 torchaudio==0.10.1+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

    这里是 PyTorch 文档的 link ,向您解释如何在 PyTorch 中使用 GPU

    1. 一个非常好的入门项目,可能每个人在开始使用机器学习时都做过,尤其是那些想要使用计算机视觉的人。使用 MNIST 数据集实现图像分类。那里有很多很棒的教程。所以一开始,所有这些新词都会让人不知所措,但我保证当你开始和编写这些教程的人说同一种语言时,它会变得更好。因此,首先按照教程进行操作,如果您不理解任何单词,请自行在 Google 上搜索并逐步完成,否则,将很难理解。在您获得一些基本知识后,您可以开始构建自己的小项目。从一些小事开始。所以继续打磨:)

    【讨论】:

    • 我想你的意思是:“删除行with torch.set_grad_enabled(True):
    • no false bc 他需要将值设置为 true
    猜你喜欢
    • 1970-01-01
    • 2019-11-29
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-20
    相关资源
    最近更新 更多