diff --git a/llama_cpp/_internals.py b/llama_cpp/_internals.py index cde52c8c8..35abfa537 100644 --- a/llama_cpp/_internals.py +++ b/llama_cpp/_internals.py @@ -76,7 +76,7 @@ def free_model(): self._exit_stack.callback(free_model) def close(self): - if self.sampler is not None: + if hasattr(self, "sampler") and self.sampler is not None: # NOTE: Must remove custom samplers before free or llama.cpp will try to free them for i, _ in reversed(self.custom_samplers): llama_cpp.llama_sampler_chain_remove(self.sampler, i)