Comments (11)
Hi @mauriciocm9 ,
I could not reproduce the issue that you had.
package main
import (
"fmt"
"github.com/sugarme/gotch"
ts "github.com/sugarme/gotch/tensor"
)
func main() {
tensorA := ts.MustOnes([]int64{2, 2}, gotch.Float, gotch.CPU)
tensorB := ts.MustZeros([]int64{2, 2}, gotch.Float, gotch.CPU)
input := ts.NewIValue([]ts.Tensor{*tensorA, *tensorB})
fmt.Printf("%v\n", input)
}
// output:
// &{[{{0x251a6c0} {0x60a3e0} Tensor} {{0x251a820} {0x60a3e0} Tensor}] {0x600f20} TensorList}
My box version:
- go version go1.16.2 linux/amd64
- gotch version: v0.3.9
What gotch version are you using at your end?
from gotch.
yes, thank you, that works i was converting tensorA and tensorB to IValue. Now i'm facing an issue when using ForwardIs panic: interface conversion: interface {} is []tensor.IValue, not []tensor.Tensor
. What i'm trying to do, is feed a Tuple[Tensor, Tensor] to a model using CModule
from gotch.
Would you mind giving a simplified example that causes the panic? And full panic log please as I don't know where the panic occured.
from gotch.
package main
import (
"log"
"github.com/sugarme/gotch"
ts "github.com/sugarme/gotch/tensor"
)
func main() {
model, err := ts.ModuleLoad("torchtest/modelito.pt")
if err != nil {
println("Failed module load")
log.Fatal(err)
}
tensorA := ts.MustOnes([]int64{2, 2}, gotch.Float, gotch.CPU)
tensorB := ts.MustZeros([]int64{2, 2}, gotch.Float, gotch.CPU)
input := ts.NewIValue([]ts.Tensor{*tensorA, *tensorB})
output, err := model.ForwardIs([]ts.IValue{*input})
if err != nil {
println("error in forward", err.Error())
}
println(output)
}
Any model can work here since this happens before AtmForward
from gotch.
Can you paste the panic log please?
from gotch.
panic: interface conversion: interface {} is []tensor.IValue, not []tensor.Tensor
goroutine 1 [running]:
github.com/sugarme/gotch/tensor.(*IValue).ToCIValue(0xc000050e70, 0x6314c0, 0xc000050df8, 0x6314c0)
/home/truora/go/pkg/mod/github.com/sugarme/[email protected]/tensor/jit.go:337 +0x2ee5
github.com/sugarme/gotch/tensor.(*CModule).ForwardIs(0xc0000b2040, 0xc000105f48, 0x1, 0x1, 0x0, 0x0, 0x0)
/home/truora/go/pkg/mod/github.com/sugarme/[email protected]/tensor/jit.go:1070 +0x3a5
main.main()
/home/truora/go/src/bitbucket.org/truora/scrap-services/main.go:22 +0x265
exit status 2
go version go1.16.2 linux/amd64
from gotch.
I can reproduce the panic now. Seem to be type casting here. Does this way work for you?
import (
"log"
"github.com/sugarme/gotch"
ts "github.com/sugarme/gotch/tensor"
)
func main() {
model, err := ts.ModuleLoad("torchtest/modelito.pt")
if err != nil {
println("Failed module load")
log.Fatal(err)
}
tensorA := ts.MustOnes([]int64{2, 2}, gotch.Float, gotch.CPU)
tensorB := ts.MustZeros([]int64{2, 2}, gotch.Float, gotch.CPU)
ivalueA := ts.NewIValue(*tensorA)
ivalueB := ts.NewIValue(*tensorB)
output, err := model.ForwardIs([]ts.IValue{*ivalueA, *ivalueB})
if err != nil {
println("error in forward", err.Error())
}
println(output)
}
Or you can try with ForwardTs
?
from gotch.
i already tried both options, the models seem to only accept a tuple of tensors, the only way its works for me is:
package main
import (
"log"
"github.com/sugarme/gotch"
ts "github.com/sugarme/gotch/tensor"
)
func main() {
model, err := ts.ModuleLoad("torchtest/modelito.pt")
if err != nil {
println("Failed module load")
log.Fatal(err)
}
tensorA := ts.MustOnes([]int64{2, 2}, gotch.Float, gotch.CPU)
tensorB := ts.MustZeros([]int64{2, 2}, gotch.Float, gotch.CPU)
ivalueA := ts.NewIValue(*tensorA)
ivalueB := ts.NewIValue(*tensorB)
tupleOfTensor := ts.NewIValue([]ts.IValue{*ivalueA, *ivalueB})
output, err := model.ForwardIs([]ts.IValue{*tupleOfTensor})
if err != nil {
println("error in forward", err.Error())
}
println(output)
}
But as mentioned in the issue, i had to edit jit.go:
case "slice": // line 91
switch reflect.TypeOf(v).Elem().String() {
case "tensor.IValue":
from gotch.
Hi @mauriciocm9 ,
I have tried to fix the issue in branch jit
. Can you test it by updating gotch to jit
branch:
go get -u github.com/sugarme/gotch@jit
and try the previous code : (you might have to change the tensor input shape and type according to your model requirement).
package main
import (
"log"
"github.com/sugarme/gotch"
ts "github.com/sugarme/gotch/tensor"
)
func main() {
model, err := ts.ModuleLoad("torchtest/modelito.pt")
if err != nil {
println("Failed module load")
log.Fatal(err)
}
// NOTE. change tensor shape and type here according to your model requirement
tensorA := ts.MustOnes([]int64{2, 2}, gotch.Float, gotch.CPU)
tensorB := ts.MustZeros([]int64{2, 2}, gotch.Float, gotch.CPU)
input := ts.NewIValue([]ts.Tensor{*tensorA, *tensorB})
output, err := model.ForwardIs([]ts.IValue{*input})
if err != nil {
println("error in forward", err.Error())
}
println(output)
}
Let me know how you go, thanks.
from gotch.
yes, it works, thanks
from gotch.
@mauriciocm9 ,
Thanks for your feedback. I am closing the issue for now. Will merge in the next release.
from gotch.
Related Issues (20)
- v2.0 support HOT 3
- Possible Memory Leak From C.malloc(0) HOT 3
- how to load model pytorch_model.bin HOT 5
- Indexing documentation HOT 1
- Can't build project with gotch v0.9.0 HOT 3
- Production use for gotch just for inference HOT 3
- Concurrency issue in generating tensor name in newTensor HOT 3
- Can memory leak in tensor-generated.go because of malloc(0) ? HOT 8
- Memory Leak in JIT Model under Multi-Goroutine Environment HOT 9
- how can i convert gocv.Mat image data to Tensor ? HOT 2
- `*ts.CModule` does not implement `ts.Module` interface correctly
- Cannot Run the Application with Cgo HOT 1
- Cannot Run the Application using Libtorch 2.1 (CPU) Docker Image
- Consider using build tags instead of a bash script HOT 6
- TestOptimizer is flaky
- install steps on macos HOT 3
- Cgo Memory Leak HOT 13
- Q) Is there a function or method to clear the cached memory? HOT 1
- Float64Values() shows an error 'Unsupported Go type: []float64' HOT 2
- Releasing tensor causes segmentation fault error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gotch.