Giter Club home page Giter Club logo

mxnet.rb's Introduction

MXNet

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file lib/mxnet. To experiment with that code, run bin/console for an interactive prompt.

TODO: Delete this and the text above, and describe your gem

Installation

Add this line to your application's Gemfile:

gem 'mxnet'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mxnet

Usage

TODO: Write usage instructions here

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/mrkn/mxnet.

NOTE: Don't use RuboCop in this project

We don't want to use RuboCop because we can manage our coding style by ourselves. We want to accept small fluctuations in our coding style because we use Ruby. Please do not submit issues and PRs that aim to introduce RuboCop in this repository.

NOTE: Don't contaminate any styling changes in your pull-requests

We want any pull-requests to consist of changes only that are essential for the purposes of the pull-requests. Please do not contaimnate any styling changes in your pull-requests.

License

The gem is available as open source under the terms of the MIT License.

mxnet.rb's People

Contributors

ljulliar avatar mrkn avatar toddsundsted avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mxnet.rb's Issues

mxnet/lr_scheduler missing

I just updated my local git repo with your latest commits. When i issue a require 'mxnet' I get the following error:

> require 'mxnet'
LoadError: cannot load such file -- mxnet/lr_scheduler
	from /big/misc/applications/Ruby/extensions/mxnet/mxnet.rb/lib/mxnet.rb:32:in `require'

May you forgot to commit the lr_scheduler file ?

PS: I keep working on spec files

Indication in readme for which MXNet versions are supported

I haven't been able to see other than by dates of commits which version of MXNet this gem requires. Could indication be made.

Reason for needing to know is for the c api compatability. As far as I'm aware there have been significant internal changes to MXNet, including the deprecation of the Symbolic api

Optimisers

Part of the coverage lists

  • SGD
  • Signum
  • FTML
  • LARS
  • LBSGD
  • LAMB
  • DCASGD
  • NAG
  • SGLD
  • -ccSGD- **NOT IMPLEMENTED (DEPRECATED) Use SGD
  • Adam
  • AdaGrad
  • RMSProp
  • AdaDelta
  • Ftrl
  • Adamax
  • Nadam
  • Updater

Is this project still alive?

Hi,

I'm interested in MXnet support for Ruby, and I was wondering if this project is still alive or if it's been frozen in favor of other efforts toward the implementation of Ruby as API language for MXnet.

Stefano

Error in Symbol.var spec

I tried to fix the following test Error in symbol but couldn't find the root cause. May be in symbol.c

1) MXNet::Symbol.var 
    Failure/Error: sym.send :set_attributes, **attr
    
    TypeError:
      no implicit conversion of Symbol into String
    # ./lib/mxnet/symbol.rb:371:in `set_attributes'
    # ./lib/mxnet/symbol.rb:371:in `var'
    # ./spec/mxnet/symbol_spec.rb:15:in `block (3 levels) in <module:MXNet>'

Gluon Support

Part of coverage lists

Activations

  • LeakyReLU
  • PReLU
  • ELU
  • SELU
  • GELU
  • Swish

Layers

  • Sequential

  • HybridSequential

  • Dense

  • Dropout

  • BatchNorm

  • Embedding

  • Flatten

  • InstanceNorm

  • LayerNorm

  • GroupNorm

  • Lambda

  • HybridLambda

  • _Conv

  • Conv1D

  • Conv2D

  • Conv3D

  • Conv1DTranspose

  • Conv2DTranspose

  • Conv3DTranspose

  • _Pooling

  • MaxPool1D

  • MaxPool2D

  • MaxPool3D

  • AvgPool1D

  • AvgPool2D

  • AvgPool3D

  • GlobalMaxPool1D

  • GlobalMaxPool2D

  • GlobalMaxPool3D

  • GlobalAvgPool1D

  • GlobalAvgPool2D

  • GlobalAvgPool3D

  • ReflectionPad2D
    RNN

  • GRU Cell

  • LSTM Cell

  • GRU Layer

  • LSTM Layer

Loss

  • L2Loss
  • L1Loss
  • SigmoidBinaryCrossEntropyLoss
  • SoftmaxCrossEntropyLoss
  • KLDivLoss
  • CTCLoss
  • HuberLoss
  • HingeLoss
  • SquaredHingeLoss
  • LogisticLoss
  • TripletLoss
  • PoissonNLLLoss
  • CosineEmbeddingLoss
  • SDMLLoss

Free MXNet engine from the GVL for true parallel processing

When multiple libraries that rely heavily on CPU time are being utilised within Ruby such as MXNet, they contend for CPU time.
MXNet is designed for parallel processing and hence it does not make sense to keep the engine bound within the GVL.
For best performance the mxnet engine should be initialised outside the context of the Ruby GVL. We rely on the incubator MXNet team to do their parallel processing with threads correctly.

Infer Methods Crash without Keyword Arguments

The following both cause the Ruby runtime to crash:

a = MXNet::Symbol.var('a')
a.send(:infer_shape_impl, false) # => crash
a.infer_type # => crash

The cause is access to a NULL/nil value in the respective C functions.

See #29 for a fix.

How to code 2 fixed position arguments method

Hi,

I'm currently trying to implement NDArray.zeros_like (see https://mxnet.incubator.apache.org/api/python/ndarray/ndarray.html#mxnet.ndarray.NDArray.zeros_like )

I tried writing something like

    def self.ones_like(lhs, rhs, *args, **kwargs)
      Ops.zeros_like(lhs, rhs, *args, **kwargs)
    end

But then I get the following error when trying to call the method:

 2) MXNet::NDArray.zeros_like 
     Failure/Error: def #{op_info.func_name}(#{signature.join(', ')})
     
     ArgumentError:
       wrong number of arguments (given 2, expected 0..1)
     # ./lib/mxnet/ndarray/operation_delegator.rb:66:in `zeros_like'
     # ./spec/mxnet/ndarray_spec.rb:340:in `block (3 levels) in <module:MXNet>'

It looks like operation delegation only works form method with one fixed position argument whereas zeros_like has two.
How to work around that ?

Thank you.

MXNet::NDArray methods cause TypeError

The following code causes "no implicit conversion of Array into Integer (TypeError)".

require "mxnet"
a = MXNet::NDArray.new([[1,2,3],[4,5,6]])
p a.shape

Crash After Calling `MXNet::NDArray.new`

Something as simple as the following causes a crash locally, for me:

$ ./bin/console
[1] pry(main)> MXNet::NDArray.new

Invoking MXNet::NDArray.new constructs an invalid instance. Specifically, ndarray_allocate() is called but a handle is never allocated, so future calls to mxnet_ndarray_get_handle() return NULL which breaks code that doesn't deal with this case (including inspecting the resulting instance).

There isn't any obvious use case for MXNet::NDArray.new and the Python API doesn't have an equivalent, so I simply redefined it to raise an error in the following PR: #26

Segfaults | Memory corruption errors

I'm receiving some strange errors when using this gem in conjunction with eventmachine.

I'm rewriting values into a single NDArray instance (reused). Up to 140 writes per second.

Randomly my event loop crashed from mxnet segfault errors. I'm going to push a list of errors in this thread.

These errors appear regardless of my context, so for simplicity, assume these are in CPU context.

1.)
malloc_consolidate(): invalid chunk size

2.) In this error, there are sometimes unicode characters present for attributes as opposed to blank

ruby/2.6.0/bundler/gems/mxnet.rb-edc85f60baa5/lib/mxnet/ndarray/operation_delegator.rb:91:in `imperative_invoke': MXNetError: Cannot find argument '', Possible Arguments: (MXNet::Error)
----------------
scalar : double, optional, default=0
    The scalar value for assignment.
begin : Shape(tuple), required
    starting indices for the slice operation, supports negative indices.
end : Shape(tuple), required
    ending indices for the slice operation, supports negative indices.
step : Shape(tuple), optional, default=[]
    step for the slice operation, supports negative values.
, in operator _slice_assign_scalar(name="", scalar="267.55", step="[1, 1]", end="[181, 1]", ="[180, 0]")

3.) basic_string::_M_construct null not valid

Run MXNet engine using Ruby Ractors (Ruby 3.x)

In order to allow true parallel execution by mxnet engine, mxnet library should run within its own Ractor.

The ractor's thread lock should be unlocked to allow the MXNet threaded engine's thread pool to run in parallel.

Passing a Hash to reshape() Causes a Crash

If a is an instance of MXNet::NDArray, then a.reshape({1 => 2}) causes a crash. The usage of rb_check_convert_type(...) should be replaced with rb_convert_type(...).

See the following PR for a fix and a test: #31

Collect the rules of API design policy

We import Gluon API mainly from Python's implementation.
Make our Gluon API appropriate to Ruby's programming style, we need to collect the rules of API design.

Collected rules

  • Do not import function-style constructor from Python

Incosistent index OOB slice behaviour between 1-D and N-D NDArrays.

When slicing out of bounds of 1-D NDArray, an exception occurs correctly.

require 'mxnet'

a = MXNet::NDArray.ones([5])
a[0..7]

git/mxnet.rb/lib/mxnet/ndarray.rb:121:in '_slice' MXNet::Error (MXNetError: Check failed: shape_[0] >= end (5 vs. 8) : Slice end index out of range)

When slicing out of bounds of N-D NDArray, the OOB is ignored and as much as possible of the slice is returned.

require 'mxnet'

a = MXNet::NDArray.ones([5,5])
a[0, 0..7]

[1, 1, 1, 1, 1] <MXNet::NDArray 5 @cpu(0)>

require 'mxnet'

a = MXNet::NDArray.ones([5,5])
a[0..7, 2]

[1, 1, 1, 1, 1] <MXNet::NDArray 5 @cpu(0)>

Consistent error behaviour is expected between these methods.

Contributing to mxnet.rb

Hi mrkn,

I'm thinking of contributing to mxnet.rb. Before I start doing things On my own I'd like to get a status from you on the things that you believe must be done in priority. Thank you for your guidance

Laurent

Guidance on method definition

I was about to write the spec for NDArray#sqrt when I realized that as it is today I can only call:

z = MXNet::NDArray.sqrt(x)
which means NDArray.sqrt (class method)

I guess for #sqrt to work I need to implement

def sqrt
....
end

in NDArray Ruby class, right ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.