wansenai / eairp

✨ Saas Enterprise Resource Planning (开源Sass ERP系统)
http://eairp.cn
Apache License 2.0
57 stars 21 forks source link

Explanation of Air module used for training models #119

Open Jzow opened 8 months ago

Jzow commented 8 months ago

Usually, the training of models and reasoning is done through the low-level implementation, so we will not use Java to train models and reasoning regarding the air module.

  1. The first is: because it is within the jvm

  2. The second point is that Java is a high-performance language, but in the AI field, Python and are usually more favored. This is because many AI libraries in Python use high-performance C/C++ implementations at the bottom

[dependencies]
tensorflow = { version = "0.21.0", features = ["tensorflow_gpu"] }
tensorflow-sys = { version = "0.24.0", features = ["tensorflow_gpu"] }

But we chose to use Rust and Tensorflow to train and validate the model, and then Java would call the model code in memory provided by Rust.

Fortunately, we use Java 21 and no longer need to use JNI to call it. Instead, we would choose the methods of external functions and memory API's, such as Arena.

@Benchmark
public int getMemUnitPanama() throws Throwable {
    try (Arena arena = Arena.ofConfined()) {
        MemorySegment info = arena.allocate(sysinfoLayout);
        getMemUnit.invokeExact(info);
        return (int) memUnitHandle.get(info);
    }
}
Jzow commented 8 months ago

Supplement: We will collect data and train the model only after completing 70% of the business function development progress

Jzow commented 8 months ago

In the article on infoq, we saw an article about foreign Function & Memory API to Bridge the Gap between Java and Native Libraries

url: Java External Function API