Skip to content

Commit

Permalink
[python] log exception stacktrace for exceptions in python, improve r…
Browse files Browse the repository at this point in the history
…eturned error message on KeyErrors during parse input
  • Loading branch information
siddvenk committed Jul 2, 2024
1 parent 59706f7 commit f9d8b95
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion engines/python/setup/djl_python/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ def _read_model_config(self, model_config_path: str):
except Exception as e:
logging.error(
f"{model_config_path} does not contain a config.json or adapter_config.json for lora models. "
f"This is required for loading huggingface models")
f"This is required for loading huggingface models",
exc_info=True)
raise e


Expand Down
3 changes: 2 additions & 1 deletion engines/python/setup/djl_python/sm_log_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def filter(self, record):
return False
except Exception as exc:
logging.warning(
f"Forwarding {str(record)} failed due to {str(exc)}")
f"Forwarding {str(record)} failed due to {str(exc)}",
exc_info=True)
return False

def count(self, key):
Expand Down
1 change: 1 addition & 0 deletions engines/python/setup/djl_python/streaming_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def run_generation(model, **kwargs):
try:
model.generate(**kwargs)
except Exception as e:
logging.warning("stream generation failed", exc_info=True)
streamer.put_text(str(e))
finally:
streamer.end()
Expand Down
10 changes: 8 additions & 2 deletions engines/python/setup/djl_python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ def parse_input_with_formatter(inputs: Input,
adapters_per_item, found_adapter_per_item = _parse_adapters(
_inputs, input_map, item, adapter_registry)
except Exception as e: # pylint: disable=broad-except
logging.warning(f"Parse input failed: {i}")
input_size.append(0)
errors[i] = str(e)
err_msg = "Input Parsing failed. Ensure that the request payload is valid. "
# str(e) for KeyError only yields the name of the key, which isn't useful as a response to the client
if isinstance(e, KeyError):
err_msg += f"Invalid Request Property: {e}"
else:
err_msg += str(e)
errors[i] = err_msg
logging.warning(err_msg, exc_info=True)
continue

input_data.extend(_inputs)
Expand Down

0 comments on commit f9d8b95

Please sign in to comment.