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

Add offline mode with tests #177

Merged
merged 6 commits into from
Mar 4, 2025
Merged

Conversation

ardaatahan
Copy link
Contributor

This PR aims to bring offline mode logic to swift-transformers:

  • Adds useOfflineMode flag to snapshot function to give developers explicit control over offline behavior without relying on automatic network detection
  • Adds NetworkMonitor class to detect network connectivity state (connected/expensive/constrained), which is useful to decide whether to use offline mode when the developers have no explicit preference
  • Implements offline file validation by checking local files, metadata integrity, and LFS file hashes
  • Adds new OfflineModeError cases and improves error handling
  • Adds FileManager extension to support recursive file enumeration
  • Reorganizes code by moving metadata helper functions to HubApi level and simplifying HubFileDownloader, which makes them easier to use for offline mode file verification

These changes enable the library to work reliably without network access and help reduce bandwidth usage on mobile devices with limited connectivity or cellular data plans. This is particularly important for ML models which can be quite large, ensuring users don't unexpectedly consume large amounts of mobile data when models are already present locally.

@FL33TW00D
Copy link
Collaborator

Seems testDeepSeekQwenChatTemplate is failing here

@ardaatahan
Copy link
Contributor Author

It's because the test case in main is validating an outdated chat template output. I updated that test case to validate the correct output tokens in this pr: #175

@ZachNagengast
Copy link
Collaborator

Yea the template itself changed on the source repo - see this commit https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B/commit/6602cadec947dbb53e64f3d8d6425320b2197247 #175 has the fix but could also be part of its own PR, since main tests would currently fail if ran again due the them changing the template in the model repo

@FL33TW00D
Copy link
Collaborator

Please rebase when you're ready now that #175 is merged :)

@ardaatahan
Copy link
Contributor Author

@FL33TW00D thanks! I just merged the recent changes

@FL33TW00D
Copy link
Collaborator

Happy to merge this if we can confirm that #180 is solved!

@FL33TW00D FL33TW00D merged commit 1a926a2 into huggingface:main Mar 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants