详细内容或原文请订阅后点击阅览
torch 0.2.0 - 初始 JIT 支持和许多错误修复
torch 0.2.0 版本包含许多错误修复和一些不错的新功能,如初始 JIT 支持、多工作器数据加载器、新优化器和 nn_modules 的新打印方法。
来源:RStudio AI博客我们很高兴地宣布,torch 0.2.0 版本刚刚登陆 CRAN。
torch
此版本包含许多错误修复和一些不错的新功能,我们将在本篇博文中介绍。您可以在 NEWS.md 文件中查看完整的变更日志。
NEWS.md我们将详细讨论的功能包括:
- 对 JIT 跟踪的初始支持多工作程序数据加载器nn_modules 的打印方法
nn_modules
多工作程序数据加载器
数据加载器现在响应 num_workers 参数并将在并行工作程序中运行预处理。
dataloaders
num_workers
例如,假设我们有以下执行长时间计算的虚拟数据集:
library(torch)dat <- dataset( "mydataset", initialize = function(time, len = 10) { self$time <- time self$len <- len }, .getitem = function(i) { Sys.sleep(self$time) torch_randn(1) }, .length = function() { self$len })ds <- dat(1)system.time(ds[1])
library(torch)dat <- dataset( "mydataset",initialize = function(time, len = 10) { self$time <- time self$len <- len }, .getitem = function(i) { Sys.sleep(self$time) torch_randn(1) }, .length = function() { self$len })ds <- dat(1)system.time(ds[1])
library(torch)
library
library
(
torch
torch
)
dat <- dataset(
dat
<-
dataset
(
"mydataset",
"mydataset"
initialise = function(time, len = 10) {
=
函数
(
时间
len
=
10
)
{
self$time <- time
self
$
时间
<-
时间
self$len <- len
self
$
len
<-
len
},
}
.getitem = function(i) {
=
函数
(
i
)
{
Sys.sleep(self$time)
Sys.sleep
Sys.sleep
(
self
$
时间
)
torch_randn(1)
torch_randn
(
1
)
},
}
.length = function() {
=
函数
(
)
{
self$len
self
$
len
}
}
)
)
ds < - dat(1)
ds
<-
dat
(
1
)
system.time(ds[1])
system.time
system.time
(
ds
[
1
]
)
用户系统已用 0.029 0.005 1.027
用户系统已用 0.029 0.005 1.027
我们现在将创建两个数据加载器,一个按顺序执行,另一个并行执行。
seq_dl <- 数据加载器(ds,batch_size = 5)par_dl <- 数据加载器(ds,batch_size = 5,num_workers = 2)seq_dl <- 数据加载器 ( ds = 5 )