[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:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user