You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When specifying a Numpy array with Shape and DType, we get an error concerning the deletion of remaining_annotations.
When looking at the responsible code (here) this makes sense.
Using del in the list you are looping over will change it while looping over it. So, in this case, it will remove Shape first, and then with i==1 it will try to remove DType as well. However, since Shape was already removed, DType is now at index 0, and not at index i, which is why the code fails.
When does it happen
fromtypingimportAnnotatedimportbentomlimportnumpyasnpfrombentoml.validatorsimportDType, Shape# Other code @bentoml.apidefpredict_all(
self,
spectrum: Annotated[np.ndarray, Shape((246,)), DType("float32")]
=Field(description="A 1x4 tensor with float32 dtype")
) ->np.ndarray:
returnnp.mean([model.predict(spectrum) formodelinself.models])
Solution
# Still remaining after numpy annotations are processed.remaining= []
forannotationin (remaining_annotations):
ifisinstance(annotation, Shape):
shape=annotation.dimensionselifisinstance(annotation, DType):
dtype=annotation.dtypeelse:
remaining.append(annotation)
returnsource, [TensorSchema("numpy-array", dtype, shape), *remaining]
Describe the bug
When specifying a Numpy array with
Shape
andDType
, we get an error concerning the deletion ofremaining_annotations
.When looking at the responsible code (here) this makes sense.
Using
del
in the list you are looping over will change it while looping over it. So, in this case, it will removeShape
first, and then withi==1
it will try to removeDType
as well. However, sinceShape
was already removed,DType
is now at index 0, and not at indexi
, which is why the code fails.When does it happen
Solution
Shall I make a PR?
To reproduce
No response
Expected behavior
No response
Environment
Environment variable
System information
bentoml
: 1.2.4python
: 3.12.3platform
: Linux-5.15.146.1-microsoft-standard-WSL2-x86_64-with-glibc2.31uid_gid
: 0:0pip_packages
The text was updated successfully, but these errors were encountered: