FluxML / FluxJS.jl

I heard you like compile times
Other
42 stars 8 forks source link

Add more broadcastable primitives #13

Closed amellnik closed 6 years ago

amellnik commented 6 years ago

This allows leakyrelu to work in a single-layer net, but not inside of Chain for some reason that I haven't been able to figure out.

jekbradbury commented 6 years ago

This works for me on your branch?

julia> @code_js Chain(Dense(10, 5, leakyrelu), Dense(5, 1))(rand(10))
let model = (function () {
  let math = dl.ENV.math;
  function hornet(tiger) {
    return math.add(math.matrixTimesVector(model.weights[0], tiger), model.weights[1]);
  };
  function turkey(toad) {
    return math.relu(math.add(math.matrixTimesVector(model.weights[2], toad), model.weights[3]), 0.01);
  };
  function model(aardvark) {
    return hornet(turkey(aardvark));
  };
  model.weights = [];
  return model;
})();
flux.fetchWeights("model.bson").then((function (ws) {
  return model.weights = ws;
}));

This also works:

@code_js Chain(Dense(10, 5, leakyrelu), Dense(5, 5), x -> leakyrelu.(x))(rand(10))
amellnik commented 6 years ago

@jekbradbury -- You are correct. I was trying to do

@code_js Chain(Dense(32, 128, leakyrelu), Dense(128, 784))(zeros(Float32, 32))

instead of

@code_js Chain(Dense(32, 128, leakyrelu), Dense(128, 784))(rand(32))

which works. I don't know why it makes a difference, but it's not related to these changes.

jekbradbury commented 6 years ago

Well, rand would give Float64, which I think is Flux's default for parameters.

On Mon, Apr 2, 2018 at 11:27 AM Alex Mellnik notifications@github.com wrote:

@jekbradbury https://github.com/jekbradbury -- You are correct. I was trying to do

@code_js Chain(Dense(32, 128, leakyrelu), Dense(128, 784))(zeros(Float32, 32))

instead of

@code_js Chain(Dense(32, 128, leakyrelu), Dense(128, 784))(rand(32))

which works. I don't know why it makes a difference, but it's not related to these changes.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/FluxML/FluxJS.jl/pull/13#issuecomment-378002510, or mute the thread https://github.com/notifications/unsubscribe-auth/ALL4tvJnqfFbBRAiqhP2PgP4vofL_dakks5tkm2egaJpZM4S8HkV .

amellnik commented 6 years ago

Closing in favor of #15.