-
Notifications
You must be signed in to change notification settings - Fork 46
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
JIT model multiple inputs #20
Comments
Just managed to make the multi-inputs work.
However I'm still clueless for the multi-outputs. I coudn't find any function that allows the output to be a slice. |
Although JIT API has not been complete yet, gotch provides 2 APIs to forward pass CModule:
Have a look at JIT unit test for how to use. Also, there 2 separate examples of using JIT in example folder: inference and train Not sure if that what you're after? |
Have you handled error in |
Hi, Thanks for the hints! the error was coming from Converting the input tensors to
Now I would just figure out how to get the three Tensors back out of the |
Something like var output []ts.Tensor
output = prediction.Value().([]ts.Tensor) |
I'm really new to Go, as you can tell - and the concept of |
I think the issue is related to type casting inside gotch JIT itself and it may fall into one of the unsupported cases. As you mentioned output is Can you try to cast in var output []interface{}
output = prediction.Value().([]interface{})
// Or just
output := prediction.Value() If you can share your JIT module |
Hi, gave it a try: Here's the jit model: Update:
works. Easy fix for the problem, as there is no advantage of using Tuple over List really. |
A fix #20 done on package main
import (
"fmt"
"log"
"github.com/sugarme/gotch"
ts "github.com/sugarme/gotch/tensor"
)
func main() {
input_ids, _ := ts.Ones([]int64{2, 73}, gotch.Int64, gotch.CPU)
input_mask, _ := ts.Ones([]int64{2, 73}, gotch.Int64, gotch.CPU)
input_ids_ival := ts.NewIValue(*input_ids)
input_mask_ival := ts.NewIValue(*input_mask)
inputs := []ts.IValue{*input_ids_ival, *input_mask_ival}
model, err := ts.ModuleLoad("distilled_scripted.pt")
if err != nil {
log.Fatal(err)
}
prediction, err := model.ForwardIs(inputs)
if err != nil {
log.Fatal(err)
}
xs := prediction.Value().([]ts.Tensor)
for _, x := range xs {
fmt.Printf("%i", &x)
}
}
// Output: TENSOR INFO:
Shape: [2 6]
DType: float32
Device: {CPU 1}
Defined: true
TENSOR INFO:
Shape: [2 70 37]
DType: float32
Device: {CPU 1}
Defined: true
TENSOR INFO:
Shape: [2 70]
DType: int64
Device: {CPU 1}
Defined: true
|
Hi, just came across your project, Great work, seem to be the only go bindings that actually work!
I have a jitted model taking two inputs and returning multiple outputs.
In C++, this seems to be done like this:
pytorch/pytorch#18337
How would I do this in gotch?
Forward
only accepts a single tensor.The text was updated successfully, but these errors were encountered: