Skip to content

WIP feat:Init commit for rust backend #1180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed

WIP feat:Init commit for rust backend #1180

wants to merge 18 commits into from

Conversation

Aisuko
Copy link
Collaborator

@Aisuko Aisuko commented Oct 17, 2023

Description

This PR relates to #939

Notes for Reviewers

Signed commits

  • Yes, I signed my commits.

@Aisuko Aisuko marked this pull request as draft October 17, 2023 02:38
@Aisuko Aisuko self-assigned this Oct 17, 2023
Signed-off-by: GitHub <noreply@github.com>
@mudler
Copy link
Owner

mudler commented Oct 17, 2023

cc @lu-zero

Aisuko and others added 3 commits October 18, 2023 10:47
Co-authored-by: Luca Barbato <luca.barbato@gmail.com>
Signed-off-by: Aisuko <urakiny@gmail.com>
Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: Aisuko <urakiny@gmail.com>
@Aisuko Aisuko requested a review from lu-zero October 18, 2023 08:00
@Aisuko Aisuko requested a review from lu-zero October 19, 2023 04:51
Signed-off-by: Aisuko <urakiny@gmail.com>
Co-authored-by: Luca Barbato <luca.barbato@gmail.com>
Signed-off-by: Aisuko <urakiny@gmail.com>
Signed-off-by: Aisuko <urakiny@gmail.com>
@Aisuko Aisuko requested a review from lu-zero October 20, 2023 01:09
Signed-off-by: Aisuko <urakiny@gmail.com>
@Aisuko
Copy link
Collaborator Author

Aisuko commented Oct 22, 2023

The process of rust backend:

  • The basic framework of Rust gRPC backend (Maybe still some issues, will fixed by other commits)
  • Implement with burn (Working on it now, their website was broken I already open issue on their repo and do more investigation)
  • candle (I see burn support candle as backend in alpha. So, let's implement the backend with burn first)

Really appreciate your help @lu-zero but still need your help on "burn" backend, thank you.

Signed-off-by: Aisuko <urakiny@gmail.com>
Co-authored-by: Luca Barbato <luca.barbato@gmail.com>
Signed-off-by: Aisuko <urakiny@gmail.com>
Signed-off-by: Aisuko <urakiny@gmail.com>
@Aisuko
Copy link
Collaborator Author

Aisuko commented Oct 26, 2023

An idea of choosing default burn backend for Rust backend #1219

@Aisuko
Copy link
Collaborator Author

Aisuko commented Oct 31, 2023

Get stuck in some issues like below(only in debug mode), it may related to the Rust implement PyTorch C++ API.

dyld[15803]: Library not loaded: @rpath/libtorch_cpu.dylib
  Referenced from: <B583CD33-2743-323A-B503-5781B34C078F> /Users/tifa/Downloads/workspace/LocalAI/backend/rust/target/debug/deps/server-bc3eca19368e3b4a
  Reason: no LC_RPATH's found

It makes hard to debug the program. I am going to refactor some code and add setting file of IDE. Make sure it can be easy for anyone to debug the program.

@lu-zero
Copy link
Collaborator

lu-zero commented Oct 31, 2023

it seems to look for libtorch and fails to find it. if you use the ndarray backend does it work?

@Aisuko
Copy link
Collaborator Author

Aisuko commented Oct 31, 2023

it seems to look for libtorch and fails to find it. if you use the ndarray backend does it work?

Will try it and give a feedback

Update

ndarary backend can be used to debug in IDE. And the torch backend has some issues on Mac M1. Here I am trying to set up LIBTORCH_USE_PYTORCH=1 as env with the conda env which is installed PyTorch. However, it is still hit other issues on M1 environment. So, I'm going to use ndarray to help me debug the conversion part code.

@lu-zero
Copy link
Collaborator

lu-zero commented Nov 1, 2023

On the M1 probably the wgpu backend is the nicest to use, but ndarray is the one that does not depend on the host system.

Signed-off-by: Aisuko <urakiny@gmail.com>
Signed-off-by: Aisuko <urakiny@gmail.com>
@Aisuko
Copy link
Collaborator Author

Aisuko commented Nov 1, 2023

On the M1 probably the wgpu backend is the nicest to use, but ndarray is the one that does not depend on the host system.

Thanks a lot. I have made some change here. I have been migrated the code which is included Llama2 to fork repo, and I am working on the a more simpler model. Here are some reasons:

  • A simpler model can be more effecient to debug than Llama2, less parameters, and less memory used. (Only load half of Llama2 parameters to tensor can cost at least 13min in my local env now)
  • We can move faster on this PR. It is good for us to refractor the code, project structure and abstract some common traits.
  • Easy for code reviewing
  • Easy for adding some test cases(CI).

Here I hit an issue on reshaping of the Tensor. So, we can try to implement a simple one instead of getting stuck on the Llama2.
Screenshot 2023-11-01 at 5 32 21 pm

Signed-off-by: Aisuko <urakiny@gmail.com>
Signed-off-by: Aisuko <urakiny@gmail.com>
@Aisuko Aisuko mentioned this pull request Nov 5, 2023
93 tasks
// And now the nonlinear scale
let min_log_hz = 1000.0; // beginning of log region (Hz)
let min_log_mel = (min_log_hz - f_min) / f_sp;
let logstep = (6.4f64).ln() / 27.0; // step size for log region
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those constants are repeated, being always f64 you can just keep them as consts

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, will do.

Signed-off-by: Aisuko <urakiny@gmail.com>
Signed-off-by: Aisuko <urakiny@gmail.com>
Signed-off-by: Aisuko <urakiny@gmail.com>
Copy link

netlify bot commented Nov 23, 2023

Deploy Preview for localai failed.

Name Link
🔨 Latest commit c990112
🔍 Latest deploy log https://app.netlify.com/sites/localai/deploys/655ea7b3d02aec0008ca4cdf


let tensor3=tensor2.transpose();

let tensor41=tensor3.repeat(2, 2);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lu-zero Here, I am going to use wgpu backend instead of tch. However, I the repeat function here only support 2 dimensions tensor, (Can only repeat dimension with dim=1) https://github.com/Tracel-AI/burn/blob/b86bc5876149bd73bc59cb5197fd3ee8b92509d4/burn-tensor/src/tensor/ops/tensor.rs#L222C7-L222C7.

I have been tried several solutions, like use swap_dims and flattern these internal function of Tensor, but here hard to say it is correct and also causes other issues. Is there a better example for this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asking upstream probably it is the best route (sorry for the belated reply, I got very busy and the message got lost in the mailbox)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, thanks for your support. I will continue to work on this one after I applied PhD successfully. Currently, sooo busy. But I still want to get this PR to merged.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you are more free please contact me, probably a good deal of the issues will be ironed out by upstream meanwhile :)

@Aisuko Aisuko closed this by deleting the head repository Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants