Skip to content
Open
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
3 changes: 2 additions & 1 deletion Tests/ModelsTests/WeightsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ struct WeightsTests {
@Test("Load weights from file URL")
func loadWeightsFromFileURL() async throws {
let repo = "google/bert_uncased_L-2_H-128_A-2"
let modelDir = try await hubApi.snapshot(from: repo, matching: ["config.json", "model.safetensors"])
let onlineHubApi = HubApi(downloadBase: downloadDestination, useOfflineMode: false)
let modelDir = try await onlineHubApi.snapshot(from: repo, matching: ["config.json", "model.safetensors"])

let files = try FileManager.default.contentsOfDirectory(at: modelDir, includingPropertiesForKeys: [.isReadableKey])
#expect(files.contains(where: { $0.lastPathComponent == "config.json" }))
Expand Down
8 changes: 4 additions & 4 deletions Tests/TokenizersTests/FactoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import Hub
import Testing
import Tokenizers

private func makeHubApi() -> (api: HubApi, downloadDestination: URL) {
private func makeHubApi(useOfflineMode: Bool? = nil) -> (api: HubApi, downloadDestination: URL) {
let base = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
let destination = base.appending(component: "huggingface-tests-\(UUID().uuidString)")
return (HubApi(downloadBase: destination), destination)
return (HubApi(downloadBase: destination, useOfflineMode: useOfflineMode), destination)
}

@Suite("Factory")
Expand All @@ -40,7 +40,7 @@ struct FactoryTests {

@Test
func fromModelFolder() async throws {
let (hubApi, downloadDestination) = makeHubApi()
let (hubApi, downloadDestination) = makeHubApi(useOfflineMode: false)
defer { try? FileManager.default.removeItem(at: downloadDestination) }

let filesToDownload = ["config.json", "tokenizer_config.json", "tokenizer.json"]
Expand All @@ -54,7 +54,7 @@ struct FactoryTests {

@Test
func whisperFromModelFolder() async throws {
let (hubApi, downloadDestination) = makeHubApi()
let (hubApi, downloadDestination) = makeHubApi(useOfflineMode: false)
defer { try? FileManager.default.removeItem(at: downloadDestination) }

let filesToDownload = ["config.json", "tokenizer_config.json", "tokenizer.json"]
Expand Down
2 changes: 1 addition & 1 deletion Tests/TokenizersTests/TokenizerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ struct TokenizerTests {
return base.appending(component: "hf-local-pretrained-tests-downloads")
}()

let hubApi = HubApi(downloadBase: downloadDestination)
let hubApi = HubApi(downloadBase: downloadDestination, useOfflineMode: false)
let downloadedTo = try await hubApi.snapshot(from: "pcuenq/gemma-tokenizer")

let tokenizerOpt = try await AutoTokenizer.from(modelFolder: downloadedTo) as? PreTrainedTokenizer
Expand Down