FluxML / FluxML/Torch.jl

error: `getindex not defined for Tensor{Float32,2}`

Open
#43 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
240
Forks
18
PR merge metrics
No merged PRs in 30d

Description

Hello,

I am implementing a very simple example with Torch.jl, and I get the following error: `getindex not defined for Tensor{Float32,2}`. The code works for `cpu` and `gpu`, and it is as follows:

```
using Flux
using Flux: params, update!, Losses
using CUDA
using Dates: now
using Statistics: mean
using Random
using Torch
using Torch: torch

if CUDA.has_cuda_gpu()
#device = gpu;
device = torch;
println("Training on GPU")
println(" - CUDA version: $(CUDA.version())")
println(" - Device: $(CUDA.name(CUDA.CuDevice(0)))")
else
device = cpu;
println("Training on CPU")
end

model = Chain(
Dense(10, 128, relu),
Dense(128, 128, relu),
Dense(128, 1)
) |> device

p = params(model)

opt = ADAM(3e-4)

x = rand(Float32, 10, 2000) |> device
y = rand(Float32, 1, 2000) |> device

function loss(x, y)
ŷ = model(x)
return Losses.mse(ŷ, y; agg=mean)
end

for j = 1:10
st = now()
for i = 1:10
g = gradient(() -> loss(x, y), p)
update!(opt, p, g)
end
println(now() - st)
end
```

My system information is this:

```
Julia Version 1.5.1
Commit 697e782ab8 (2020-08-25 20:08 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Xeon(R) CPU @ 2.20GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, broadwell)
Environment:
JULIA_NUM_THREADS = 4
```
GPU info:

```
CUDA version: 10.1.0
Device: Tesla T4
```

Packages info:
```
CUDA v2.3.0
Flux v0.11.2
IJulia v1.23.1
Torch v0.1.2
```
Thanks.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.