MCPcopy Create free account
hub / github.com/PAIR-code/lit / pred_lock_key

Method pred_lock_key

lit_nlp/lib/caching.py:121–142  ·  view source on GitHub ↗

Get the key for the predictions lock for the provided cache keys.

(self, keys: list[CacheKey])

Source from the content-addressed store, hash-verified

119 return fs
120
121 def pred_lock_key(self, keys: list[CacheKey]) -> Optional[PredLockKey]:
122 """Get the key for the predictions lock for the provided cache keys."""
123 fs = self._construct_pred_lock_key(keys)
124
125 # If the provided cache keys already have a lock, return the key.
126 if fs in self._pred_locks:
127 return fs
128 # If there is a lock for a superset of the provided cache keys, return the
129 # key to that lock.
130 # This means that requests for subsets of data already being predicted will
131 # wait for the larger set of predictions to complete. This can slow down
132 # certain single-example requests but leads to more efficient use of the
133 # model. We may have duplicate predict calls for an example to a model if
134 # one example is part of separate but distinct predict calls with different
135 # subsets of examples, but this is unlikely given how LIT predict requests
136 # work.
137 for key in self._pred_locks:
138 if fs.issubset(key):
139 return key
140 # Otherwise, return None as there is no lock yet for the provided cache
141 # keys.
142 return None
143
144 def get_pred_lock(self, keys: list[CacheKey]) -> threading.RLock:
145 """Gets the lock for the provided cache keys, creating one if neccessary."""

Callers 5

get_pred_lockMethod · 0.95
delete_pred_lockMethod · 0.95
test_pred_lock_keyMethod · 0.95
predictMethod · 0.80

Calls 1