My Little Garden of Code

Jun 20, 2018 - 4 minute read - Comments

Translating PyTorch models to Flux.jl Part2: Running on GPU

In the previous post I translated a simple PyTorch RNN to Flux.jl a machine learning framework for Julia. Here’s the Julia code modified to use the GPU (and refactored a bit from the previous version; I’ve put the prediction section into a predict function): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 using Flux using Flux.

Jun 15, 2018 - 5 minute read - Comments

Translating PyTorch models to Flux.jl Part1: RNN

Flux.jl is a machine learning framework built in Julia. It has some similarities to PyTorch, and like most modern frameworks includes autodifferentiation. It’s definitely still a work in progress, but it is being actively developed (including several GSoC projects this summer). I was curious about how easy/difficult it might be to convert a PyTorch model into Flux.jl. I found a fairly simple PyTorch tutorial on RNNs to translate. My goal here isn’t to explain RNNs (see the linked article for that) - my intent is to see what is required to go from the PyTorch/Python ecosystem to the Flux.

Jun 11, 2018 - 2 minute read - Comments -

Migrated blog from Octopress to Hugo

I went to add a new blog post last week and then tried to run octorpress to generate the static html for the blog as I had been doing in the past. But of course it wasn’t so simple. I’d upgraded my dev machine to Ubuntu 18.04 a few weeks back and Octopress wasn’t happy with the version of Ruby I had. When I went to try to build the old version of Ruby that it wanted, that build failed (likely something is more strict in gcc-7.

Feb 6, 2017 - 1 minute read - Comments -

Testing MathJax

\[f(x;\mu,\sigma^2) = \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{1}{2}\left(\frac{x-\mu}{\sigma}\right)^2}\] $$ \begin{align} \mbox{Union: } & A\cup B = \{x\mid x\in A \mbox{ or } x\in B\} \\ \mbox{Concatenation: } & A\circ B = \{xy\mid x\in A \mbox{ and } y\in B\} \\ \mbox{Star: } & A^\star = \{x_1x_2\ldots x_k \mid k\geq 0 \mbox{ and each } x_i\in A\} \\ \end{align} $$ \[e^{i \pi} + 1 = 0\]

Feb 2, 2017 - 2 minute read - Comments -

FUNemployment

I finished up a 16-month LLVM contracting gig at the end of 2016. Got the flu a couple of weeks ago and have been pretty much out of commission until today when I finally had enough mental clarity and energy to get this blog going again. Since I last posted in 2014 it seems that Octopress has been updated. I had to go back to my old desktop machine and find where all the blog-related files were and transfer them to my current desktop machine.

Sep 10, 2014 - 5 minute read - Comments -

Some notes on building and running mirage unikernels on Cubieboard2

First a caveat: These notes reflect the state of Mirage as of the date of this post. Mirage is still in heavy development and the instructions here will change (hopefully become simpler) going forward. These are some notes on what I had to do to get a Mirage unikernel running under Xen on a cubieboard2. The intent here is to document some of the gotchyas I ran into. Installing Xen for ARM on Cubieboard

Jul 9, 2014 - 6 minute read - Comments -

Cooperative Concurrency in OCaml: A Core.Std.Async example

I’ve been working on an OCaml Mqtt client for eventual use with MirageOS. Mqtt is a lightweight publish/subscribe messaging transport protocol that’s aimed at embedded systems and IoT applications. Without going into much detail about the protocol, implementing it requires some form of concurrency as there is a keep-alive ping that needs to be sent from the client to the broker at regular intervals to keep the connection alive. The client can also be receiving messages from the broker and needs to be able to queue up those messages for processing.

May 30, 2014 - 6 minute read - Comments -

stop the presses ocaml wins

###Benchmarking is a tricky thing. Several sharp eyes noticed some flaws in the OCaml code in my last post. The main problem was pointed out by Kim Nguyễn in the comments: your OCaml version is flawed… First in F# you do every computation in integer and only convert as float at the end (it seems). If you do the same in OCaml, you will gain some speed, that is: list_sum should use 0 and +, and distance should use let x = a - b in x*x to compute the square and only call “float” before sqrt, as you do in F# (and therefore also call float at the end on num_correct since list_sum now returns an integer.

May 29, 2014 - 10 minute read - Comments -

Comparing a Machine Learning algorithm implemented in F Sharp and OCaml

(UPDATE: please see the next post: Stop the Presses: OCaml wins in terms of speed in which it is shown that there were some serious flaws in my OCaml implementation below. I’ll keep this post around for reference.) I’ve been dabbling with OCaml for the last several years and so when I saw a recent Meetup notice about an F# machine learning code dojo being led by Mathias Brandewinder within walking distance of my house I thought I’d check it out.

May 14, 2014 - 13 minute read - Comments -

Drawing Happy Little Trees: tree meditation number 2

In the previous Tree Meditation we pondered some preliminary ideas about treeness. Now let’s think about how to draw our trees. Before we start, make sure you paste this tree type code from the last installment into the Try OCaml REPL: 1 type 'a tree = Empty | Leaf of 'a | Node of 'a tree * 'a * 'a tree Last time we coded our little tree using the constructors Empty, Leaf, and Node defined in our tree type: