spring-projects / spring-ai

An Application Framework for AI Engineering
https://docs.spring.io/spring-ai/reference/index.html
Apache License 2.0
3.25k stars 830 forks source link

Latest DJL dependencies cause incompatibility for PyTorch in MacOS x86_64 #1371

Open tzolov opened 1 month ago

tzolov commented 1 month ago

DJL versions >= 0.29.0 doesn't support PyTorch for MacOS x86_64.

Additional context: https://github.com/spring-projects/spring-ai/commit/df17f08f5b7c22b31ac73893b90d621180856774#commitcomment-146828827

fjtorres commented 1 month ago

I just tested your suggestion and it's working without issues. My test case was really quite simple but it's the same that was failing yesterday on my laptop.

import org.junit.jupiter.api.Test;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class MainTest {

    @Autowired
    EmbeddingModel embeddingModel;

    @Test
    void generateSimpleEmbedding() {
        embeddingModel.embed("Simple text for embedding");
    }
}
fjtorres commented 1 month ago

Checking DJL documentation, they added a comment about this topic here.

tzolov commented 1 month ago

Thank you for checking it out.

Looks like DJL is not going to try to provide some form of backward compatibility for MacOS x86_64.

The explicit downgrading to 0.28.0 seems to be the only workaround i can think of. Thanks for confirming it works. I'm coping it here for are reference. Perhaps we can add it to the Spring Ai docs as well:

        <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-transformers-spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>ai.djl.pytorch</groupId>
                    <artifactId>pytorch-engine</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>ai.djl</groupId>
                    <artifactId>api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>ai.djl</groupId>
                    <artifactId>model-zoo</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>ai.djl.huggingface</groupId>
                    <artifactId>tokenizers</artifactId>
                </exclusion>

            </exclusions>
        </dependency>

        <dependency>
            <groupId>ai.djl.pytorch</groupId>
            <artifactId>pytorch-engine</artifactId>
            <version>0.28.0</version>
        </dependency>
        <dependency>
            <groupId>ai.djl</groupId>
            <artifactId>api</artifactId>
            <version>0.28.0</version>
        </dependency>
        <dependency>
            <groupId>ai.djl</groupId>
            <artifactId>model-zoo</artifactId>
            <version>0.28.0</version>
        </dependency>
        <dependency>
            <groupId>ai.djl.huggingface</groupId>
            <artifactId>tokenizers</artifactId>
            <version>0.28.0</version>
        </dependency>