Skip to content

[cm] Custom Neutone exceptions#58

Open
christhetree wants to merge 1 commit into
mainfrom
cm--exceptions
Open

[cm] Custom Neutone exceptions#58
christhetree wants to merge 1 commit into
mainfrom
cm--exceptions

Conversation

@christhetree
Copy link
Copy Markdown
Collaborator

This PR implements Neutone exceptions which are used when other exceptions have cryptic error messages that should be elaborated on.

Currently takes advantage of the raise from functionality introduced in python 3, let me know if you think there's a nicer way to do this.

@christhetree christhetree self-assigned this Oct 27, 2023
Comment thread neutone_sdk/utils.py
sqw = SampleQueueWrapper(model)

with tr.no_grad():
with tr.inference_mode():
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this inference_mode block here?

Comment thread neutone_sdk/benchmark.py
if convert_to_torchscript:
log.info("Converting to TorchScript")
with torch.no_grad():
with torch.inference_mode():
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also similar for this one, do we actually need it?

Comment thread neutone_sdk/exceptions.py


# TODO(cm): constant for now, but if we need more of these we could use a factory method
INFERENCE_MODE_EXCEPTION = NeutoneException(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a list of possible exceptions that you iterate through it in the try/catch block?

Comment thread neutone_sdk/exceptions.py
block.
""",
trigger_type=RuntimeError,
trigger_str="Inference tensors cannot be saved for backward."
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit worried about:

  • Is this specific enough to not accidentally catch other exceptions?
  • We need to test it with different pytorch versions and see if we get the same error string.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I used only a snippet of the text, but it's probably better to change it to use almost the entire text. I think it would also make sense to change this to a list of strings that can each trigger the exception such that if the text is slightly different in older pytorch versions we can simply add those messages to the list.

Comment thread neutone_sdk/benchmark.py
sort_by="self_cpu_memory_usage", row_limit=5
log.info("Displaying Total CPU Time")
log.info(prof.key_averages().table(sort_by="cpu_time_total", row_limit=10))
# log.info(prof.key_averages(group_by_stack_n=5).table(sort_by="cpu_time_total", row_limit=10))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this?

Copy link
Copy Markdown
Collaborator

@bogdanteleaga bogdanteleaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, thank you!
Left a couple of comments. I like the raise from approach, looks like we could also do a raise from None to suppress the original message. I think that's fine in this case, but maybe too much in general?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants