K8S & LESSER KNOWN
NEURAL NETWORKS IN GO
GOLANG TAIPEI GATHERING #29
Slide 2
Slide 2 text
ABOUT ME
▸ Masters in Cybernetics, CTU, Prague
▸ Started Kubernetes London Meetup
▸ Containers: https://containerops.org/
▸ Machine Learning: https://mlexplore.org/
▸ Twitter: @milosgajdos
▸ Github: milosgajdos83
Slide 3
Slide 3 text
TONIGHT
KUBERNETES LONDON MEETUP
EXTENDING K8S WITH GO
NEURAL NETWORKS IN GO
QUIZ!
Slide 4
Slide 4 text
LET’S TALK ABOUT
KUBERNETES LONDON
Slide 5
Slide 5 text
KUBERNETES LONDON MEETUP
▸ Started w/ Peter Idah
(@peteridah) in Feb 2015
▸ Currently almost 2k members
▸ Growing strong…still
Slide 6
Slide 6 text
No content
Slide 7
Slide 7 text
LET’S TALK ABOUT
KUBERNETES
Slide 8
Slide 8 text
KUBERNETES IN NUTSHELL
▸ Users interact with k8s [only] via API service
▸ Everything [useful] is an API object
▸ Users create them, Control Plane manages them
▸ Control Plane is a “Kernel”, APIs are “standard libs”
Slide 9
Slide 9 text
KUBERNETES IS THE POSIX OF
THE CLOUD
James Strachan, Redhat
Slide 10
Slide 10 text
EXTENDING
KUBERNETES [API]
Slide 11
Slide 11 text
API SERVICE SHIPS AS
A COMPILED BINARY
Slide 12
Slide 12 text
NEW K8S RELEASE
SHIPS QUARTERLY
Slide 13
Slide 13 text
CONTRIBUTING TO
K8S IS NOT EASY!
Slide 14
Slide 14 text
WHAT IF I TOLD
YOU…ABOUT CDR?
Slide 15
Slide 15 text
CUSTOM RESOURCE DEFINITION (CRD)
▸ Extend k8s API with custom objects
▸ CDRs allow to use familiar UX: kubectl
▸ On their own just “dumb” storage of structured data
▸ Powerful in combination with CONTROLLERS
Slide 16
Slide 16 text
CDR EXAMPLE
Slide 17
Slide 17 text
CRD IN ACTION
Slide 18
Slide 18 text
CONTROLLERS GIVE YOU CDR
SUPERPOWERS…SORT OF
Slide 19
Slide 19 text
CDR CONTROLLER IN ACTION
Slide 20
Slide 20 text
CONTROLLER REGISTRATION
Slide 21
Slide 21 text
CDR CONTROLLERS IN GO
▸ Easy to create, well…sort of :-)
▸ Sample controller:
https://github.com/kubernetes/sample-controller
▸ Dig into the code deeper:
https://goo.gl/d12pQK
▸ Go even deeper: API aggregation
▸ Credit: James Munnelly (@JamesMunnelly )
Slide 22
Slide 22 text
LET’S TALK ABOUT
NEURAL NETWORKS
Slide 23
Slide 23 text
WHY GO AND NEURAL NETWORKS
▸ Go is fun! Well, most of the time ;-)
▸ Statically typed language, memory safe
▸ Easy concurrency
▸ Reasonably fast [and still improving] runtime
Slide 24
Slide 24 text
PYTHON [R] + CUDA
LEADING THE WAY
Slide 25
Slide 25 text
FPGA+GO=OK FOR
SOME WORKLOADS
Slide 26
Slide 26 text
BUT STILL NOWHERE
NEAR CUDA GPU MAGIC
Slide 27
Slide 27 text
YOU NEED A GOOD
NUMERICAL LIBRARY
Slide 28
Slide 28 text
GO FOR NUMERICAL & SCIENTIFIC COMPUTING
▸ gonum: set of Go libraries for scientific computing
https://www.gonum.org
▸ Numerical computations and optimization problems:
https://github.com/gonum/gonum
▸ Particularly interesting packages:
mat: matrix operations
optimize: optimisation problems
▸ Plotting graphs:
https://github.com/gonum/plot
Slide 29
Slide 29 text
CREATE MATRIX
Slide 30
Slide 30 text
BASIC MATRIX OPERATIONS
Slide 31
Slide 31 text
TRANSFORM MATRIX OPERATIONS
Slide 32
Slide 32 text
MATRIX VIEW OPERATIONS
Slide 33
Slide 33 text
STATISTICS, COMPARISONS ETC.
Slide 34
Slide 34 text
SOME NOTES
▸ The result of Matrix operation stored in receiver:
▸ Receiver must be initialized!
▸ Receiver get mutated by the operation!
▸ Panics when the indexes are out of bounds!
▸ Some operations return Vector, not Matrix!
▸ You can access raw backing data (float64 slices)
Slide 35
Slide 35 text
LESSER KNOWN
NEURAL NETS…IN GO
Slide 36
Slide 36 text
SELF ORGANISING MAPS (SOM)
▸ Data clustering
▸ Unsupervised learning
▸ gosom: SOM implementation in Go
https://github.com/milosgajdos83/gosom
▸ http://mlexplore.org/2017/01/13/
self-organizing-maps-in-go/
Slide 37
Slide 37 text
HOPFIELD NETWORKS
▸ Associative memory
▸ Supervised learning
▸ gopfield: Hopfield networks in Go
https://github.com/milosgajdos83/gopfield
▸ http://mlexplore.org/2017/03/12/
hopfield-networks-in-go/
Slide 38
Slide 38 text
TIPS AND TRICKS
▸ Sometimes looping over a raw vector slice is faster than
multiplying vectors using mat package functions
AVOID UNNECESSARY ALLOCATIONS
▸ Avoid re-computing CPU “expensive” values (pow, exp…)
CACHE AND RE-USE EXPENSIVE COMPUTATIONS
▸ Go Profiler is pretty awesome and it’s your best friend
AVOID PREMATURE OPTIMISATIONS
Slide 39
Slide 39 text
SUMMARY
▸ Extending k8s API is simple and
can give you super powers
▸ Neural Networks in Go are fun,
but Python + CUDA still faster
▸ Stay awesome and keep
hacking in Go!
Slide 40
Slide 40 text
REFERENCES
▸ Gist from this talk
https://gist.github.com/milosgajdos83/
de311c901572644481d4b5dd3830d6cc
▸ Awesome list of Go for data science resources
https://github.com/gopherdata/resources
▸ gorgonnia = Go + CUDA
https://github.com/chewxy/gorgonia
▸ Go + FPGA
https://github.com/ReconfigureIO