Skip to content

Commit

Permalink
Fix caching offers with GPU requirements (#2210)
Browse files Browse the repository at this point in the history
Use `Requirements.json` instead of
`Requirements.dict`+`json.dumps`, which fails on
enums.

Also remove `sort_keys=True`, which seems to be
redundant.

> field order is preserved by .dict() and .json()
> etc.
https://docs.pydantic.dev/1.10/usage/models/#field-ordering
  • Loading branch information
jvstme authored Jan 23, 2025
1 parent 8cc4040 commit e47a3f2
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/dstack/_internal/core/backends/base/compute.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import os
import re
import threading
Expand Down Expand Up @@ -188,7 +187,7 @@ def _get_offers_cached_key(self, requirements: Optional[Requirements] = None) ->
# Requirements is not hashable, so we use a hack to get arguments hash
if requirements is None:
return hash(None)
return hash(json.dumps(requirements.dict(), sort_keys=True))
return hash(requirements.json())

@cachedmethod(
cache=lambda self: self._offers_cache,
Expand Down

0 comments on commit e47a3f2

Please sign in to comment.