Comments (7)
I just made a quick test by "hacking" the tensor package.
I've made a "lazy initialization" of the array; the value is populated on a call to Data()
which is not often.
The results look promising:
Normal bench:
➜ onnx-go git:(benchmarks) ✗ go test -bench=. -benchmem -memprofile memprofile.out -cpuprofile profile.out -benchtime=10s
goos: darwin
goarch: amd64
pkg: github.com/owulveryck/onnx-go
BenchmarkUnmarshalBinary-4 2000 10688594 ns/op 3906741 B/op 67107 allocs/op
PASS
ok github.com/owulveryck/onnx-go 22.620s
bench with the hack:
➜ onnx-go git:(benchmarks) ✗ go test -bench=. -benchmem -memprofile memprofile.out -cpuprofile profile.out -benchtime=10s
goos: darwin
goarch: amd64
pkg: github.com/owulveryck/onnx-go
BenchmarkUnmarshalBinary-4 3000 6136003 ns/op 2642474 B/op 27664 allocs/op
PASS
ok github.com/owulveryck/onnx-go 19.169s
from onnx-go.
This commit from then tensor.Tensor
package drastically enhances performances and memory consumption.
However, I will keep this issue open for now to do a further investigation with the broadcasting mechanism.
from onnx-go.
In Gorgonia, the broadcast mechanism is based on the repeatOp
, which itself triggers a call to Repeat(...)
in the Dense implementation of the Tensor package.
This mechanism is calling copyDenseSliced
many times in two embedded for loops. A single call to copyDenseSlice
is creating two new objects here
d := dst.arr().slice(dstart, dend)
s := src.arr().slice(sstart, send)
Within this loop, we are creating i x j x 2
strides.
We could reduce the number of creation and garbage collection by extracting the s
and d
slices from the copyDenseFunction
.
from onnx-go.
With the PR 43 from the tensor package, the results are now:
➜ onnx-go git:(benchmarks) ✗ go test -bench=. -benchmem -memprofile memprofile.out -cpuprofile profile.out -benchtime=10s
goos: darwin
goarch: amd64
pkg: github.com/owulveryck/onnx-go
BenchmarkUnmarshalBinary-4 3000 4208506 ns/op 2042788 B/op 18273 allocs/op
PASS
ok github.com/owulveryck/onnx-go 13.320s
Comparing with the initial investigation of the issue, the performance comparison will be:
benchmark old ns/op new ns/op delta
BenchmarkUnmarshalBinary-4 9457554 4528740 -52.12%
benchmark old allocs new allocs delta
BenchmarkUnmarshalBinary-4 67120 18272 -72.78%
benchmark old bytes new bytes delta
BenchmarkUnmarshalBinary-4 3910542 2042637 -47.77%
Once the PR is merged, that will be enough to close this issue
from onnx-go.
Closed thanks to PR #43 of the tensor package
from onnx-go.
I reopen this issue because on NN involving small tensors, broadcasting is ok, but on bigger tensor it's still too slow.
from onnx-go.
PR 299 from Gorgonia should improve things
from onnx-go.
Related Issues (20)
- Implement operator PRelu for backend Gorgonia
- Implement operator pRelu for backend Gorgonia
- Failed to infer shape. Op: A × Bᵀ: Inner dimensions do not match up HOT 2
- Implement operator `Gather` for backend `Gorgonia` HOT 3
- Cannot model.UnmarshalBinary - says 'No data found' HOT 1
- Can't import onnx model, converted from BigGAN-PyTorch HOT 2
- Implement operator LSTM,Clip for backend Gorgonia HOT 1
- Will this project be maintained further and are contributions still welcomed?
- Implement operator `LinearRegressor` for backend `gorgonia`
- "Asymmetric padding" error
- panic: negative dimension size does not make sense
- ../../go/src/gorgonia.org/tensor/dense_compat.go:442:23: undefined: array.Interface HOT 2
- Updated depens
- poor performance (run model)
- run() function calls newMachine() everytime HOT 1
- Question: unsqueeze: axes in not an []int64 HOT 3
- Support for empty tensors
- Tape machine does not reset properly for some models HOT 2
- Implement operator `PReLU` for backend `Gorgonia`
- Implement operator `Cast` for backend `Gorgonia`
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 onnx-go.