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

UForm for Swift 🍏 🐦 #76

Merged
merged 4 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ build/
package-lock.json
*.egg-info
*.onnx
__pycache__
__pycache__
.build
.swiftpm
13 changes: 13 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"lineLength": 120,
"indentation": {
"spaces": 4
},
"maximumBlankLines": 1,
"respectsExistingLineBreaks": true,
"lineBreakBeforeControlFlowKeywords": true,
"lineBreakBeforeEachArgument": true,
"multiElementCollectionTrailingCommas": true,
"spacesAroundRangeFormationOperators": true
}
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File with Arguments",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
}
]
}
15 changes: 14 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
{
"cSpell.words": [
"arange",
"CFURL",
"coreml",
"cumsum",
"dtype",
"embs",
"finfo",
"huggingface",
"keepdim",
"linalg",
"logits",
"Matryoshka",
"mlmodel",
"mlpackage",
"mlprogram",
"multimodal",
"ndarray",
"numpy",
"ONNX",
"onnxruntime",
"packbits",
"preprocess",
"pretrained",
"probs",
"pypi",
"rerank",
"reranker",
"reranking",
"sess",
"SIMD",
"softmax",
"transfromers",
"uform",
"unimodal",
"unsqueeze"
"unsqueeze",
"Vardanian"
],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
Expand Down
18 changes: 17 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Contributing to UForm

We welcome contributions to UForm!

## Python

Before submitting any changes, please make sure that the tests pass.

```sh
Expand All @@ -13,4 +16,17 @@ pip install -e ".[torch,onnx]" # For PyTorch and ONNX Python tests

pytest python/scripts/ -s -x -Wd -v
pytest python/scripts/ -s -x -Wd -v -k onnx # To run only ONNX tests without loading Torch
```
```

## Swift

Swift formatting is enforced with `swift-format` default utility from Apple.
To install and run it on all the files in the project, use the following command:

```bash
brew install swift-format
swift-format . -i -r
```

The style is controlled by the `.swift-format` JSON file in the root of the repository.
As there is no standard for Swift formatting, even Apple's own `swift-format` tool and Xcode differ in their formatting rules, and available settings.
22 changes: 22 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"pins" : [
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "c8ed701b513cf5177118a175d85fbbbcd707ab41",
"version" : "1.3.0"
}
},
{
"identity" : "swift-transformers",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ashvardanian/swift-transformers",
"state" : {
"revision" : "9ef46a51eca46978b62773f8887926dfe72b0ab4"
}
}
],
"version" : 2
}
41 changes: 41 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// swift-tools-version:5.9
import PackageDescription

let package = Package(
name: "UForm",
platforms: [
// Linux doesn't have to be explicitly listed
.iOS(.v16), // For iOS, version 13 and later
.tvOS(.v16), // For tvOS, version 13 and later
.macOS(.v13), // For macOS, version 10.15 (Catalina) and later
.watchOS(.v6), // For watchOS, version 6 and later
],
products: [
.library(
name: "UForm",
targets: ["UForm"]
)
],
dependencies: [
.package(
url: "https://github.com/ashvardanian/swift-transformers",
revision: "9ef46a51eca46978b62773f8887926dfe72b0ab4"
)
],
targets: [
.target(
name: "UForm",
dependencies: [
.product(name: "Transformers", package: "swift-transformers")
],
path: "swift",
exclude: ["EmbeddingsTests.swift"]
),
.testTarget(
name: "UFormTests",
dependencies: ["UForm"],
path: "swift",
sources: ["EmbeddingsTests.swift"]
),
]
)
Loading