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

panic on parallel runner #549

Open
lwch opened this issue Jun 7, 2023 · 1 comment
Open

panic on parallel runner #549

lwch opened this issue Jun 7, 2023 · 1 comment

Comments

@lwch
Copy link

lwch commented Jun 7, 2023

my code like this:

package main

import (
	"fmt"

	. "gorgonia.org/gorgonia"
	"gorgonia.org/tensor"
)

var w = tensor.New(tensor.WithShape(2, 2), tensor.WithBacking(GlorotEtAlN32(1, 2, 2)))

var xs = tensor.New(tensor.WithShape(2, 2), tensor.WithBacking([]float32{1, 2, 3, 4}))
var ys = tensor.New(tensor.WithShape(2, 2), tensor.WithBacking([]float32{5, 6, 7, 8}))

func assert(err error) {
	if err != nil {
		panic(err)
	}
}

func worker(ch chan struct{}) {
	g := NewGraph()
	x := NewMatrix(g, tensor.Float32, WithShape(2, 2), WithName("x"))
	y := NewMatrix(g, tensor.Float32, WithShape(2, 2), WithName("y"))
	wx := NodeFromAny(g, w, WithName("w"))
	pred := Must(Mul(x, wx))
	// mse
	diff := Must(Sub(y, pred))
	sqDiff := Must(Square(diff))
	loss := Must(Mean(sqDiff))
	_, err := Grad(loss, wx)
	assert(err)
	// vm
	vm := NewTapeMachine(g, BindDualValues(wx))
	defer vm.Close()
	for {
		<-ch
		Let(x, xs)
		Let(y, ys)
		assert(vm.RunAll()) // panic on this more than 10 times
		vm.Reset()
	}
}

func main() {
	ch := make(chan struct{})
	for i := 0; i < 2; i++ {
		go worker(ch)
	}
	for i := 0; i < 10000; i++ {
		ch <- struct{}{}
	}
	fmt.Println(w)
}

when i run in 1 goroutine, it works, but panic on parallel:

panic: PC 31. Failed to execute instruction Aᵀ × B      [CPU0 CPU4]     CPU20   true    false   true: Happened while attempting to execute Aᵀ × B       [CPU0 CPU4]CPU20    true    false   true. Node is 18. Register was: 20 : linAlgBinOp () × (2, 2) error: MatMul requires both operands to be matrices. Got t's shape: (), other's shape: (2, 2)

goroutine 6 [running]:
main.assert(...)
        /home/lwch/src/tnn/test/main.go:17
main.worker(0x0?)
        /home/lwch/src/tnn/test/main.go:40 +0x3d7
created by main.main
        /home/lwch/src/tnn/test/main.go:48 +0x34
exit status 2

how can i run in parallel and share the same weights

@chewxy
Copy link
Member

chewxy commented Jun 7, 2023

oh okay.. this usecase is not one that I've seen before. Let me try

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