[Core] Fix circular reference which leaked llm instance in local dev env (#4737)

Storing exception frame is extremely prone to circular refernece because it contains the reference to objects.

When tensorizer is not installed, it leaks llm instance because error frame has references to various modules which cause circular reference problem.

I also found spec decoding has a circular reference issue, and I solved it using weakref.proxy.
This commit is contained in:
SangBin Cho
2024-05-10 23:54:32 +09:00
committed by GitHub
parent dac6a3f6ed
commit 6a0f617210
4 changed files with 22 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
import copy
import weakref
from typing import List, Tuple
import torch
@@ -32,7 +33,7 @@ class MultiStepWorker(Worker):
super().init_device()
self._proposer = Top1Proposer(
self,
weakref.proxy(self),
self.device,
self.vocab_size,
max_proposal_len=self.max_model_len,

View File

@@ -1,3 +1,4 @@
import weakref
from typing import List, Optional, Tuple
import torch
@@ -37,7 +38,7 @@ class NGramWorker(LoraNotSupportedWorkerBase):
# Current only support Top1Proposer
self._proposer = Top1Proposer(
self,
weakref.proxy(self),
device=self.device,
vocab_size=self.vocab_size,
)