Skip to content
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
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Unit Tests

on:
# This runs in the context of the base of the pull request,
# rather than in the context of the merge commit.
# Maintainers must approve and we tighten permissions below.
pull_request_target:
types: [opened, synchronize, reopened]

permissions:
contents: read

jobs:
build-and-test:
uses: huggingface/hf-workflows/.github/workflows/swift_transformers_unit_tests.yml@main
with:
# Use the PR merge ref, not the head.
pr_number: ${{ github.event.pull_request.number }}
secrets: inherit

lint:
name: Lint
runs-on: macos-latest

steps:
- uses: actions/checkout@v4

- run: |
swift format lint --recursive .

- name: Suggest fixes (if check fails)
if: failure()
run: |
echo "### Here's how to fix the formatting locally:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "```bash" >> $GITHUB_STEP_SUMMARY
echo "# Format all Swift files" >> $GITHUB_STEP_SUMMARY
echo 'swift format -i --recursive .' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
58 changes: 0 additions & 58 deletions .github/workflows/format.yml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/unit-tests.yml

This file was deleted.

77 changes: 77 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"fileScopedDeclarationPrivacy": {
"accessLevel": "private"
},
"indentConditionalCompilationBlocks": false,
"indentSwitchCaseLabels": false,
"indentation": {
"spaces": 4
},
"lineBreakAroundMultilineExpressionChainComponents": false,
"lineBreakBeforeControlFlowKeywords": false,
"lineBreakBeforeEachArgument": false,
"lineBreakBeforeEachGenericRequirement": false,
"lineBreakBetweenDeclarationAttributes": false,
"lineLength": 10000,
"maximumBlankLines": 1,
"multiElementCollectionTrailingCommas": true,
"noAssignmentInExpressions": {
"allowedFunctions": [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether": false,
"reflowMultilineStringLiterals": {
"never": {}
},
"respectsExistingLineBreaks": true,
"rules": {
"AllPublicDeclarationsHaveDocumentation": false,
"AlwaysUseLiteralForEmptyCollectionInit": false,
"AlwaysUseLowerCamelCase": false,
"AmbiguousTrailingClosureOverload": true,
"AvoidRetroactiveConformances": true,
"BeginDocumentationCommentWithOneLineSummary": false,
"DoNotUseSemicolons": false,
"DontRepeatTypeInStaticProperties": true,
"FileScopedDeclarationPrivacy": true,
"FullyIndirectEnum": true,
"GroupNumericLiterals": false,
"IdentifiersMustBeASCII": true,
"NeverForceUnwrap": false,
"NeverUseForceTry": false,
"NeverUseImplicitlyUnwrappedOptionals": false,
"NoAccessLevelOnExtensionDeclaration": false,
"NoAssignmentInExpressions": true,
"NoBlockComments": true,
"NoCasesWithOnlyFallthrough": true,
"NoEmptyLinesOpeningClosingBraces": false,
"NoEmptyTrailingClosureParentheses": true,
"NoLabelsInCasePatterns": true,
"NoLeadingUnderscores": false,
"NoParensAroundConditions": true,
"NoPlaygroundLiterals": true,
"NoVoidReturnOnFunctionSignature": true,
"OmitExplicitReturns": false,
"OneCasePerLine": true,
"OneVariableDeclarationPerLine": true,
"OnlyOneTrailingClosureArgument": true,
"OrderedImports": true,
"ReplaceForEachWithForLoop": true,
"ReturnVoidInsteadOfEmptyTuple": true,
"TypeNamesShouldBeCapitalized": true,
"UseEarlyExits": false,
"UseExplicitNilCheckInConditions": true,
"UseLetInEveryBoundCaseVariable": false,
"UseShorthandTypeNames": true,
"UseSingleLinePropertyGetter": true,
"UseSynthesizedInitializer": true,
"UseTripleSlashForDocumentationComments": false,
"UseWhereClausesInForLoops": false,
"ValidateDocumentationComments": true
},
"spacesAroundRangeFormationOperators": false,
"spacesBeforeEndOfLineComments": 1,
"tabWidth": 8,
"version": 1
}
87 changes: 0 additions & 87 deletions .swiftformat

This file was deleted.

3 changes: 1 addition & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"recommendations": [
"swiftlang.swift-vscode",
"vknabel.vscode-swiftformat"
]
}
}
9 changes: 3 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
// SwiftFormat configuration to match CI
"swiftformat.configSearchPaths": [
".swiftformat"
],
// Swift language settings
"swift.path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin",
"swift.buildPath": ".build",
Expand All @@ -15,12 +11,13 @@
"editor.trimAutoWhitespace": true,
// File associations
"files.associations": {
".swift-format": "json",
"*.swift": "swift"
},
// Format on save for Swift files
"[swift]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "vknabel.vscode-swiftformat"
"editor.defaultFormatter": "swiftlang.swift-vscode"
},
// Exclude build artifacts from search
"search.exclude": {
Expand All @@ -35,6 +32,6 @@
"swift.swiftEnvironmentVariables": {
"DEVELOPER_DIR": "/Applications/Xcode.app"
},
// Disable automatic generation of launch `launch.json`
// Disable automatic generation of launch configuration (`launch.json`)
"swift.autoGenerateLaunchConfigurations": false
}
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import PackageDescription

/// Define the strict concurrency settings to be applied to all targets.
let swiftSettings: [SwiftSetting] = [
.enableExperimentalFeature("StrictConcurrency"),
.enableExperimentalFeature("StrictConcurrency")
]

let package = Package(
name: "swift-transformers",
platforms: [.iOS(.v16), .macOS(.v13)],
products: [
.library(name: "Transformers", targets: ["Tokenizers", "Generation", "Models"]),
.library(name: "Transformers", targets: ["Tokenizers", "Generation", "Models"])
],
dependencies: [
.package(url: "https://github.com/johnmai-dev/Jinja", .upToNextMinor(from: "1.3.0")),
.package(url: "https://github.com/johnmai-dev/Jinja", .upToNextMinor(from: "1.3.0"))
],
targets: [
.target(name: "Generation", dependencies: ["Tokenizers"]),
Expand Down
2 changes: 1 addition & 1 deletion Sources/Generation/GenerationConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ public extension GenerationConfig {
}
}

extension GenerationConfig: Decodable { }
extension GenerationConfig: Decodable {}
2 changes: 1 addition & 1 deletion Sources/Generation/Math.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
public enum Math {
/**
Returns the index and value of the largest element in the array.

- Parameters:
- ptr: Pointer to the first element in memory.
- count: How many elements to look at.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Hub/BOMDoubling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension Data {
// Check for \u{feff} BOM (observed in Gemma tokenizers), which is encoded as 0xef 0xbb 0xbf.
// We may need more combinations.
if b == 0x22, i + 3 < src.count,
src[i + 1] == 0xEF, src[i + 2] == 0xBB, src[i + 3] == 0xBF
src[i + 1] == 0xEF, src[i + 2] == 0xBB, src[i + 3] == 0xBF
{
// Duplicate BOM
out.append(0xEF); out.append(0xBB); out.append(0xBF)
Expand Down
8 changes: 4 additions & 4 deletions Sources/Hub/BinaryDistinct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ public extension Dictionary where Key == BinaryDistinctString {
}
}

public protocol StringConvertible: ExpressibleByStringLiteral { }
public protocol StringConvertible: ExpressibleByStringLiteral {}

extension BinaryDistinctString: StringConvertible { }
extension String: StringConvertible { }
extension NSString: StringConvertible { }
extension BinaryDistinctString: StringConvertible {}
extension String: StringConvertible {}
extension NSString: StringConvertible {}

public struct BinaryDistinctCharacter: Equatable, Hashable, CustomStringConvertible, ExpressibleByStringLiteral {
let bytes: [UInt16]
Expand Down
Loading