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

Fix AssertionError for numpy.int64 in Variable Initialization #81

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions textgrad/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def __init__(
raise Exception("If the variable does not require grad, none of its predecessors should require grad."
f"In this case, following predecessors require grad: {_predecessor_requires_grad}")

assert type(value) in [str, bytes, int], "Value must be a string, int, or image (bytes). Got: {}".format(type(value))
if isinstance(value, int):
assert isinstance(value, (str, bytes, int)) or np.issubdtype(type(value), np.integer), "Value must be a string, int, or image (bytes). Got: {}".format(type(value))
if isinstance(value, int) or np.issubdtype(type(value), np.integer):
value = str(value)
# We'll currently let "empty variables" slide, but we'll need to handle this better in the future.
# if value == "" and image_path == "":
Expand Down Expand Up @@ -354,4 +354,4 @@ def _backward_idempotent(variables: List[Variable], summation: Variable, backwar

variable.gradients.add(Variable(value=variable_gradient_value,
role_description=f"feedback to {variable.get_role_description()}"))