Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Swift Package to implement a transformers-like API in Swift

License

NotificationsYou must be signed in to change notification settings

huggingface/swift-transformers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unit Tests

This is a collection of utilities to help adopt language models in Swift apps. It tries to follow the Pythontransformers API and abstractions whenever possible, but it also aims to provide an idiomatic Swift interface and does not assume prior familiarity withtransformers ortokenizers.

Rationale and Overview

Please, checkour post.

Modules

  • Tokenizers. Utilities to convert text to tokens and back. Follows the abstractions intokenizers andtransformers.js. Usage example:
import Tokenizersfunc testTokenizer()asyncthrows{lettokenizer=tryawaitAutoTokenizer.from(pretrained:"pcuenq/Llama-2-7b-chat-coreml")letinputIds=tokenizer("Today she took a train to the West")assert(inputIds==[1,20628,1183,3614,263,7945,304,278,3122])}

However, you don't usually need to tokenize the input text yourself - theGeneration code will take care of it.

  • Hub. Utilities to download configuration files from the Hub, used to instantiate tokenizers and learn about language model characteristics.

  • Generation. Algorithms for text generation. Currently supported ones are greedy search and top-k sampling.

  • Models. Language model abstraction over a Core ML package.

Supported Models

This package has been tested with autoregressive language models such as:

  • GPT, GPT-Neox, GPT-J.
  • SantaCoder.
  • StarCoder.
  • Falcon.
  • Llama 2.

Encoder-decoder models such as T5 and Flan are currentlynot supported. They are high up in ourpriority list.

Other Tools

SwiftPM

To useswift-transformers with SwiftPM, you can add this to yourPackage.swift:

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

And then, add the Transformers library as a dependency to your target:

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

Roadmap / To Do

  • Tokenizers: download from the Hub, port fromtokenizers
  • exporters – Core ML conversion tool.
    • Allow max sequence length to be specified.
    • Allow discrete shapes
    • Returnlogits from converted Core ML model
    • Usecoremltools @main for latest fixes. In particular,this merged PR makes it easier to use recent versions of transformers.
  • Generation
    • Nucleus sampling (we currently have greedy and top-k sampling)
    • Usenewtop-k implementation inAccelerate.
    • Support discrete shapes in the underlying Core ML model by selecting the smallest sequence length larger than the input.
  • Optimization: cache past key-values.
  • Encoder-decoder models (T5)
  • Demo app
    • Allow system prompt to be specified.
    • How to define a system prompt template?
    • Test a code model (to stretch system prompt definition)

License

Apache 2.

About

Swift Package to implement a transformers-like API in Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp