Skip to content

useBackgroundDownloadSession in WhisperKitConfig is ignored during initialization #337

@bww-ios

Description

@bww-ios

When initializing WhisperKit with a WhisperKitConfig, the useBackgroundDownloadSession argument is not correctly passed to the HubAPI downloader. This prevents the use of a background URLSession for model downloads during the initialization process. The issue appears to stem from the WhisperKit convenience initializer, which doesn't seem to propagate the useBackgroundDownloadSession setting to the underlying downloader.

Steps to Reproduce

  1. Create a WhisperKitConfig with useBackgroundDownloadSession set to true:
let config = WhisperKitConfig(
    verbose: true,
    logLevel: .debug,
    prewarm: true,
    load: true,
    download: true,
    useBackgroundDownloadSession: true
)
  1. Initialize WhisperKit using this configuration:
self.whisperPipe = try await WhisperKit(config)
  1. Set a breakpoint in Downloader.swift for the swift-transformers here: https://github.com/huggingface/swift-transformers/blob/main/Sources/Hub/Downloader.swift#L64

Expected Behavior: When useBackgroundDownloadSession is true, the code execution should enter this conditional block to configure a background URLSession:

if inBackground {
    config = URLSessionConfiguration.background(withIdentifier: sessionIdentifier)
    config.isDiscretionary = false
    config.sessionSendsLaunchEvents = true
}

Actual Behavior: The if inBackground conditional evaluates to false, and the background URLSession configuration is skipped. The download proceeds using a standard URLSession.

Current Workaround: AFAIK, to enable background downloading, you must invoke the download() method directly on an already-initialized WhisperKit instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions