Giter VIP home page Giter VIP logo

mlx_usage's Introduction

mlx_usage

trying out mlx framework

Instruction substitution examples (torch -> mlx)

* view -> reshape
x = x.view(new_x_shape)
->
x = mx.reshape(x, new_x_shape)

* permute(*args) -> transpose ([*args])
x.permute(0, 2, 1, 3)
->
x.transpose([0, 2, 1, 3])

* cat -> concatenate (dim -> axis)
torch.cat([a,b], dim = 2)
->
mx.concatenate([a,b], axis = 2)

* torch.nn.functional.softmax -> mx.softmax (dim -> axis)
torch.nn.functional.softmax(attention_scores, dim = -1)
->
mx.softmax(attention_scores, axis=-1)

## Activation Layers
* GELUActivation -> mlx.nn.gelu
transformers GeLU
# https://github.com/huggingface/transformers/blob/58e7f9bb2faf30622c9bead7adf472ac59f3d301/src/transformers/activations.py#L59C7-L59C21
->
mlx.nn.GELU()

* torch.nn.Tanh() -> mx.tanh
activation = torch.nn.Tanh()
activation(x)
->
activation = mx.tanh
activation(x)

WIP - BERT

  • load_bert_test.ipynb
    • BERT code from transformers package
    • a lot of extensions were removed in WIP (ex. chunk feed forward, is_decoder checks, ..)

inference_bert.py

>>> python inference_bert.py
Loaded MLXBert: 0.008 sec
Loaded Weight: 0.006 sec
{'input_ids': array([[ 101, 7592,  102]]), 'token_type_ids': array([[0, 0, 0]]), 'attention_mask': array([[1, 1, 1]])}
[1, 3, 768]
[1, 768]
array([-0.306098, 0.262229, -0.189619, ..., 0.379691, -0.125868, -0.114839], dtype=float32)

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.