Skip to content

Commit

Permalink
Merge branch 'wzh/pplbug' into 'main'
Browse files Browse the repository at this point in the history
fix pipeline.bind bug

See merge request tps-llm/lazyllm!143
  • Loading branch information
wzh1994 committed Jun 12, 2024
2 parents 812959a + e57d6eb commit 73563fa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
6 changes: 0 additions & 6 deletions lazyllm/common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,6 @@ def __setattr__(self, __name: str, __value: Any) -> None:
return setattr(self._f, __name, __value)
return super(__class__, self).__setattr__(__name, __value)

def __enter__(self):
self._f.__enter__()
return self

def __exit__(self, exc_type, exc_val, exc_tb):
return self._f.__exit__(exc_type, exc_val, exc_tb)

setattr(builtins, 'bind', Bind)

Expand Down
1 change: 0 additions & 1 deletion lazyllm/components/auto/autodeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ def __new__(cls, base_model, source=lazyllm.config['model_source'], trust_remote
kw[value] = getattr(c, key)
return deploy_cls(trust_remote_code=trust_remote_code, launcher=launcher, stream=stream, **kw)
raise RuntimeError(f'No valid framework found, candidates are {[c.framework.lower() for c in candidates]}')

10 changes: 5 additions & 5 deletions lazyllm/components/utils/downloader/model_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ def __init__(self, model_source=lazyllm.config['model_source'],
self.token = token
self.cache_dir = cache_dir
self.model_pathes = model_path.split(":") if len(model_path) > 0 else []

@classmethod
def get_model_type(cls, model) ->str:
def get_model_type(cls, model) -> str:
assert isinstance(model, str) and len(model) > 0, "model name should be a non-empty string"
for name, info in model_name_mapping.items():
if 'type' not in info: continue
model_name_set={name.casefold()}

model_name_set = {name.casefold()}
for source in info:
if source == 'type': continue
model_name_set.add(info[source].split('/')[-1].casefold())

if model.split(os.sep)[-1].casefold() in model_name_set:
return info['type']
return 'llm'

def download(self, model=''):
assert isinstance(model, str), "model name should be a string."
if len(model) == 0 or model[0] in (os.sep, '.', '~'): return model # Dummy or local model.
Expand Down
16 changes: 14 additions & 2 deletions lazyllm/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def _add(self, k, v):
else:
lazyllm.LOG.warning(f'{k} is already defined in this scope, ignor it')

def __enter__(self):
def __enter__(self, __frame=None):
assert len(self._items) == 0, f'Cannot init {self.__class__} with items if you want to use it by context.'
self._curr_frame = inspect.currentframe().f_back
self._curr_frame = __frame if __frame else inspect.currentframe().f_back
if self._auto_capture:
self._frame_keys = list(self._curr_frame.f_locals.keys())
else:
Expand Down Expand Up @@ -85,6 +85,18 @@ def for_each(self, filter, action):
action(item)


def _bind_enter(self):
assert isinstance(self._f, FlowBase)
self._f.__enter__(inspect.currentframe().f_back)
return self

def _bind_exit(self, exc_type, exc_val, exc_tb):
return self._f.__exit__(exc_type, exc_val, exc_tb)

setattr(bind, '__enter__', _bind_enter)
setattr(bind, '__exit__', _bind_exit)


def _is_function(f):
return isinstance(f, (types.BuiltinFunctionType, types.FunctionType,
types.BuiltinMethodType, types.MethodType, types.LambdaType))
Expand Down

0 comments on commit 73563fa

Please sign in to comment.