Skip to content

Commit 9bb000d

Browse files
authored
fix(BA-926): Properly handle zero-value unknown resource limits when creating session (#3925)
1 parent 8bd924f commit 9bb000d

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

changes/3925.fix.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Properly handle zero-value unknown resource limits when creating session.

src/ai/backend/common/types.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -918,17 +918,19 @@ def from_user_input(
918918
obj: Mapping[str, Any],
919919
slot_types: Optional[Mapping[SlotName, SlotTypes]],
920920
) -> "ResourceSlot":
921+
pruned_obj = {k: v for k, v in obj.items() if v != 0}
922+
921923
try:
922924
if slot_types is None:
923925
data = {
924926
k: cls._normalize_value(k, v, cls._guess_slot_type(k))
925-
for k, v in obj.items()
927+
for k, v in pruned_obj.items()
926928
if v is not None
927929
}
928930
else:
929931
data = {
930932
k: cls._normalize_value(k, v, slot_types[SlotName(k)])
931-
for k, v in obj.items()
933+
for k, v in pruned_obj.items()
932934
if v is not None
933935
}
934936
# fill missing

src/ai/backend/manager/registry.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ async def enqueue_session(
12241224
if (resources := creation_config.get("resources")) is not None:
12251225
# Sanitize user input: does it have "known" resource slots only?
12261226
for slot_key, slot_value in resources.items():
1227-
if slot_key not in known_slot_types:
1227+
if slot_value != 0 and slot_key not in known_slot_types:
12281228
raise InvalidAPIParameters(f"Unknown requested resource slot: {slot_key}")
12291229
try:
12301230
requested_slots = ResourceSlot.from_user_input(resources, known_slot_types)

0 commit comments

Comments
 (0)