Skip to content

Commit 4f91561

Browse files
authored
CI: self-hosted runner (#75)
* CI: self-hosted runner * Fix hosted runner label * Tests: custom download location, delete when done.
1 parent 2eea315 commit 4f91561

File tree

4 files changed

+62
-15
lines changed

4 files changed

+62
-15
lines changed

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
jobs:
1111
build-and-test:
12-
runs-on: macos-13
12+
runs-on: [ self-hosted, macOS ]
1313
steps:
1414
- uses: actions/checkout@v4
1515
- name: Build

Tests/HubTests/HubTests.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,26 @@ import XCTest
99

1010

1111
class HubTests: XCTestCase {
12-
override func setUp() {
13-
// Put setup code here. This method is called before the invocation of each test method in the class.
14-
}
12+
let downloadDestination: URL = {
13+
let base = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
14+
return base.appending(component: "huggingface-tests")
15+
}()
16+
17+
override func setUp() {}
1518

1619
override func tearDown() {
17-
// Put teardown code here. This method is called after the invocation of each test method in the class.
20+
do {
21+
try FileManager.default.removeItem(at: downloadDestination)
22+
} catch {
23+
print("Can't remove test download destination \(downloadDestination), error: \(error)")
24+
}
1825
}
1926

27+
var hubApi: HubApi { HubApi(downloadBase: downloadDestination) }
28+
2029
func testConfigDownload() async {
2130
do {
22-
let configLoader = LanguageModelConfigurationFromHub(modelName: "t5-base")
31+
let configLoader = LanguageModelConfigurationFromHub(modelName: "t5-base", hubApi: hubApi)
2332
let config = try await configLoader.modelConfig
2433

2534
// Test leaf value (Int)
@@ -62,7 +71,7 @@ class HubTests: XCTestCase {
6271

6372
func testConfigCamelCase() async {
6473
do {
65-
let configLoader = LanguageModelConfigurationFromHub(modelName: "t5-base")
74+
let configLoader = LanguageModelConfigurationFromHub(modelName: "t5-base", hubApi: hubApi)
6675
let config = try await configLoader.modelConfig
6776

6877
// Test leaf value (Int)

Tests/TokenizersTests/FactoryTests.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,38 @@
77

88
import XCTest
99
import Tokenizers
10+
import Hub
1011

11-
class FactoryTests: XCTestCase {
12+
class TestWithCustomHubDownloadLocation: XCTestCase {
13+
let downloadDestination: URL = {
14+
let base = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
15+
return base.appending(component: "huggingface-tests")
16+
}()
17+
18+
override func setUp() {}
19+
20+
override func tearDown() {
21+
do {
22+
try FileManager.default.removeItem(at: downloadDestination)
23+
} catch {
24+
print("Can't remove test download destination \(downloadDestination), error: \(error)")
25+
}
26+
}
27+
28+
var hubApi: HubApi {
29+
return HubApi(downloadBase: downloadDestination)
30+
}
31+
}
32+
33+
class FactoryTests: TestWithCustomHubDownloadLocation {
1234
func testFromPretrained() async throws {
13-
let tokenizer = try await AutoTokenizer.from(pretrained: "coreml-projects/Llama-2-7b-chat-coreml")
35+
let tokenizer = try await AutoTokenizer.from(pretrained: "coreml-projects/Llama-2-7b-chat-coreml", hubApi: hubApi)
1436
let inputIds = tokenizer("Today she took a train to the West")
1537
XCTAssertEqual(inputIds, [1, 20628, 1183, 3614, 263, 7945, 304, 278, 3122])
1638
}
1739

1840
func testWhisper() async throws {
19-
let tokenizer = try await AutoTokenizer.from(pretrained: "openai/whisper-large-v2")
41+
let tokenizer = try await AutoTokenizer.from(pretrained: "openai/whisper-large-v2", hubApi: hubApi)
2042
let inputIds = tokenizer("Today she took a train to the West")
2143
XCTAssertEqual(inputIds, [50258, 50363, 27676, 750, 1890, 257, 3847, 281, 264, 4055, 50257])
2244
}

Tests/TokenizersTests/TokenizerTests.swift

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class TokenizerTester {
8383
private var edgeCases: [EdgeCase]? = nil
8484
private var _tokenizer: Tokenizer? = nil
8585

86-
init(hubModelName: String, encodedSamplesFilename: String, unknownTokenId: Int?) {
87-
configuration = LanguageModelConfigurationFromHub(modelName: hubModelName)
86+
init(hubModelName: String, encodedSamplesFilename: String, unknownTokenId: Int?, hubApi: HubApi) {
87+
configuration = LanguageModelConfigurationFromHub(modelName: hubModelName, hubApi: hubApi)
8888
self.encodedSamplesFilename = encodedSamplesFilename
8989
self.unknownTokenId = unknownTokenId
9090

@@ -198,17 +198,33 @@ class TokenizerTests: XCTestCase {
198198

199199
// Known id retrieved from Python, to verify it was parsed correctly
200200
class var unknownTokenId: Int? { nil }
201-
201+
202+
static var downloadDestination: URL = {
203+
let base = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
204+
return base.appending(component: "huggingface-tests")
205+
}()
206+
207+
class var hubApi: HubApi { HubApi(downloadBase: downloadDestination) }
208+
202209
override class func setUp() {
203210
if let hubModelName = hubModelName, let encodedSamplesFilename = encodedSamplesFilename {
204211
_tester = TokenizerTester(
205212
hubModelName: hubModelName,
206213
encodedSamplesFilename: encodedSamplesFilename,
207-
unknownTokenId: unknownTokenId
214+
unknownTokenId: unknownTokenId,
215+
hubApi: hubApi
208216
)
209217
}
210218
}
211-
219+
220+
override class func tearDown() {
221+
do {
222+
try FileManager.default.removeItem(at: downloadDestination)
223+
} catch {
224+
print("Can't remove test download destination \(downloadDestination), error: \(error)")
225+
}
226+
}
227+
212228
func testTokenize() async {
213229
if let tester = Self._tester {
214230
await tester.testTokenize()

0 commit comments

Comments
 (0)