(self)
| 78 | self._exit_stack.callback(free_model) |
| 79 | |
| 80 | def close(self): |
| 81 | if self.sampler is not None: |
| 82 | # NOTE: Must remove custom samplers before free or llama.cpp will try to free them |
| 83 | for i, _ in reversed(self.custom_samplers): |
| 84 | llama_cpp.llama_sampler_chain_remove(self.sampler, i) |
| 85 | self.custom_samplers.clear() |
| 86 | self._exit_stack.close() |
| 87 | |
| 88 | def __del__(self): |
| 89 | self.close() |