Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lbotecur opened this issue Dec 30, 2020 · 1 comment
Open

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

lbotecur opened this issue Dec 30, 2020 · 1 comment

Comments

@lbotecur
Copy link

lbotecur commented Dec 30, 2020

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.

@emailweixu
Copy link

emailweixu commented Apr 27, 2021

Got same problem with Julia 1.6.

julia> a=Torch.Tensor(3,4, dev=-1)
3×4 Torch.Tensor{Float32, 2}:
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
julia> a[1,1]
ERROR: getindex not defined for Torch.Tensor{Float32, 2}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants