Giter VIP home page Giter VIP logo

Comments (11)

sugarme avatar sugarme commented on June 1, 2024

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.

mauriciocm9 avatar mauriciocm9 commented on June 1, 2024

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.

sugarme avatar sugarme commented on June 1, 2024

@mauriciocm9 ,

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.

mauriciocm9 avatar mauriciocm9 commented on June 1, 2024
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.

sugarme avatar sugarme commented on June 1, 2024

Can you paste the panic log please?

from gotch.

mauriciocm9 avatar mauriciocm9 commented on June 1, 2024
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.

sugarme avatar sugarme commented on June 1, 2024

@mauriciocm9

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.

mauriciocm9 avatar mauriciocm9 commented on June 1, 2024

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.

sugarme avatar sugarme commented on June 1, 2024

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.

mauriciocm9 avatar mauriciocm9 commented on June 1, 2024

yes, it works, thanks

from gotch.

sugarme avatar sugarme commented on June 1, 2024

@mauriciocm9 ,
Thanks for your feedback. I am closing the issue for now. Will merge in the next release.

from gotch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.