Skip to content
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

Added Hub and Tokenizers libraries. #166

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

greenrazer
Copy link
Collaborator

Added Hub and Tokenizers as separate library products in Package.swift. This change should enable selective compilation of specific components while maintaining a single project structure.

Usage Example

Usage is pretty simple, I created an external project and all that was needed was to edit Package.swift.

Specifically, Add the package dependency:

dependencies: [
        .package(url: "https://github.com/huggingface/swift-transformers", branch: "main")
    ],

Then import specific products as dependencies of the desired target:

targets: [
        .target(
            ...
            dependencies: [
                .product(name: "Hub", package: "swift-transformers")
            ]
        ),

Testing

In the external project I copied and ran all the Tokenizer, and Hub tests from swift-transformers.

  • Successfully imported both products
  • All tests passed:
    • Hub: 14 tests passed in 9.822s
    • Tokenizers: 96 tests passed in 26.948s

Copy link
Member

@pcuenca pcuenca left a comment

Choose a reason for hiding this comment

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

According to my tests, all the package dependencies are downloaded and resolved (so other dependencies are recursively pulled as well). However, they are not compiled if they don't participate in the targets used by the client package. (Actually, there's a pre-processing step where stubs and headers are generated, but no actual compilation happens).

I tested building with swift build and Xcode, using a dependent package that uses the Tokenizers library (without Models).

Package.swift Outdated
@@ -8,6 +8,8 @@ let package = Package(
platforms: [.iOS(.v16), .macOS(.v13)],
products: [
.library(name: "Transformers", targets: ["Tokenizers", "Generation", "Models"]),
.library(name: "Hub", targets: ["Hub"]),
.library(name: "Tokenizers", targets: ["Tokenizers", "Models"]),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.library(name: "Tokenizers", targets: ["Tokenizers", "Models"]),
.library(name: "Tokenizers", targets: ["Tokenizers"]),

This would pull most of the library, wouldn't it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I was getting an error with tokenizers when I didn't have the Models target, but I think that was just an issue with the test. I implemented the above change and fixed the test, and re-tested it in the external project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants