Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/heretic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def run():
start_time = time.perf_counter()
responses = model.get_responses(prompts)
end_time = time.perf_counter()
except Exception as error:
except (RuntimeError, ValueError, TypeError, OSError) as error:
if batch_size == 1:
# Even a batch size of 1 already fails.
# We cannot recover from this.
Expand Down
2 changes: 1 addition & 1 deletion src/heretic/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def __init__(self, settings: Settings):
],
max_new_tokens=1,
)
except Exception as error:
except (RuntimeError, ValueError, TypeError) as error:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In src/heretic/model.py, the from_pretrained call can raise an OSError (for example, due to a network timeout, DNS failure, or a missing/corrupted file in the local cache). If the user has configured multiple dtypes (e.g., ["bfloat16", "float16"]) and the first one fails to load due to an OSError (e.g., because its files are not cached and the system is offline), the program will crash immediately instead of falling back to the next dtype (which might be fully cached and working). To ensure the robustness of the dtype fallback mechanism, OSError should also be caught here, similar to how it was added to the exception handler in src/heretic/main.py.

Suggested change
except (RuntimeError, ValueError, TypeError) as error:
except (RuntimeError, ValueError, TypeError, OSError) as error:

self.model = None # ty:ignore[invalid-assignment]
empty_cache()

Expand Down
Loading