lucasavila00

lucasavila00

I’m hacking around, trying to support Elixir as a target for m2cgen.

To be able to merge the support for Elixir on m2cgen, the test suite needs to pass and execute in a reasonable amount of time.

So far, with the help of @josevalim I was able to optimize the tree-based models well enough that they’re no longer a problem for running the test suite.

However, SVM-Like models are too slow to compile.

Here there are 4 examples of the same model, exported with varying max line-lengths for the sub-expressions.

Varying the max length of the lines made no difference in compilation times, but the super_small version makes it easier to read and understand what the code is doing.

In the end, I need help figuring out if there’s a way to generate better code for these expressions, in order to make compilation times faster.

First Post!

josevalim

josevalim

Creator of Elixir

The first thing that comes to mind in the SVM code is:

  1. you are converting everything to a binary first thing. don’t do that for anything from m2cgen. if the goal is to work with large amounts of data, lists are not a good representation, at all. Instead expect the input to be a binary.

  2. you are reading the same input multiple times. This was not a problem in the other examples but seems to be one for SVM. So I would do this as the first thing on top:

<<v1::float, v2::float, v3::float, ...>> = input

And then use v1, v2, instead of calling read. Not sure how much it helps, but it should help a bit.

Last Post!

lucasavila00

lucasavila00 OP

I created a “benchmark” for the compiler, where I have a function return one expression. I control the length of said expression (the 1+1+1 part)

defmodule Test do

  def run() do
    1 + 1 + 1 .....
  end
end

I benchmarked and charted it, where X is the amount of "1"s and Y is seconds to compile.

The compiler presents quadratic behaviour, given the expression size:

Then, I decided to try to wrap the each line in https://github.com/lucasavila00/ex_m2cgen_examples/blob/main/nusvm_model/super_small_lines.ex with an anonymous function.

When wrapped, the quadratic behaviour is gone, and the file compiles in ~3s now.

For the record, I can now run the entire test suite (186 models) in 10 minutes, which is totally fine for m2cgen CI, I guess. All tests passing :confetti_ball:

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

Agostinho1965
Hey everyone — I’m putting together a practical, code-first book on building production-ready business applications with Phoenix LiveView...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews