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
11 changes: 11 additions & 0 deletions bindings/chatllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,17 @@ def save_session(self, file_name: str) -> str:
def load_session(self, file_name: str) -> str:
return self._lib.load_session(self._chat, file_name)

def destroy(self) -> int:
if hasattr(self, "_chat") and self._chat:
if self.is_generating: self.abort()
obj_id = LibChatLLM._obj2id.get(self)
if obj_id is not None:
LibChatLLM._obj2id.pop(self, None)
LibChatLLM._id2obj.pop(obj_id, None)
self._lib.destroy(self._chat)
self._chat = None
return 0

def callback_print_reference(self, s: str) -> None:
self.references.append(s)

Expand Down
9 changes: 9 additions & 0 deletions src/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,15 @@ namespace chatllm
qa_encoder->set_tokenizer(this);
}

BaseTokenizer::~BaseTokenizer()
{
if (tp)
{
delete tp;
tp = nullptr;
}
}

void BaseTokenizer::set_chat_encoder(BaseHistoryEncoder *encoder)
{
chat_encoder = encoder;
Expand Down
2 changes: 1 addition & 1 deletion src/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ namespace chatllm
BaseHistoryEncoder *qa_encoder = nullptr,
BaseHistoryEncoder *completion_encoder = nullptr);

virtual ~BaseTokenizer() = default;
virtual ~BaseTokenizer();

virtual size_t load(tokenizer::DataReader *buffer, int n_vocab) = 0;

Expand Down
10 changes: 9 additions & 1 deletion src/layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ namespace chatllm
PreludeCacheDisable(void): disabler(new BlockParams::DisableCache())
{
}
virtual ~PreludeCacheDisable()
{
if (disabler)
{
delete disabler;
disabler = nullptr;
}
}
protected:
BlockParams::DisableCache *disabler;
};
Expand Down Expand Up @@ -1421,7 +1429,7 @@ namespace chatllm
sinks(BlockParams::CoreAttentionUseSinks::get() > 0 ?
ggml::new_tensor_1d(ctx, ggml::type::GGML_TYPE_F32, BlockParams::CoreAttentionUseSinks::get())
: nullptr),
pos_helper(helper ? helper : &def_pos_helper)
pos_helper(helper ? helper : new BaseTensorPosHelper(max_length))
{
allocate_pos_tensor(ctx);
}
Expand Down
9 changes: 9 additions & 0 deletions src/models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,15 @@ namespace chatllm
layer_ids.push_back(i);
}

BaseModelForConditionalGeneration::~BaseModelForConditionalGeneration()
{
if (transformer)
{
delete transformer;
transformer = nullptr;
}
}

void BaseModelForConditionalGeneration::set_layer_ids(const std::vector<int> &ids)
{
CHATLLM_CHECK((int)ids.size() == config_.num_hidden_layers) << "length(layer_ids) must be " << config_.num_hidden_layers;
Expand Down
2 changes: 1 addition & 1 deletion src/models_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ namespace chatllm
{
public:
BaseModelForConditionalGeneration(ModelType model_type, BaseConfig config, const RuntimeConfig &runtime_config, size_t GRAPH_SIZE = 4096);
virtual ~BaseModelForConditionalGeneration() = default;
virtual ~BaseModelForConditionalGeneration();

void set_layer_ids(const std::vector<int> &ids) override;
int get_max_length(void) override;
Expand Down
4 changes: 4 additions & 0 deletions src/tokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class TextPrepAddLeadingSpace : public TextPreprocessor
class DataReader
{
public:
virtual ~DataReader() {}

virtual int64_t tell() = 0;
virtual void seek(int64_t offset, int whence) = 0;
virtual int64_t size(void) const { return _size; }
Expand Down Expand Up @@ -136,6 +138,8 @@ class Processor
vocab_.byte_fallback_ready = false;
}

virtual ~Processor() {}

virtual size_t Load(DataReader *data_reader, int n_vocab) = 0;

virtual int PieceToId(std::string_view piece) const;
Expand Down
Loading