MCPcopy Index your code
hub / github.com/mudler/LocalAI / LoadModel

Method LoadModel

backend/python/diffusers/backend.py:497–661  ·  view source on GitHub ↗
(self, request, context)

Source from the content-addressed store, hash-verified

495 return backend_pb2.Reply(message=bytes("OK", 'utf-8'))
496
497 def LoadModel(self, request, context):
498 try:
499 print(f"Loading model {request.Model}...", file=sys.stderr)
500 print(f"Request {request}", file=sys.stderr)
501 torchType = torch.float32
502 variant = None
503
504 if request.F16Memory:
505 torchType = torch.float16
506 variant = "fp16"
507
508 options = request.Options
509
510 # empty dict
511 self.options = {}
512
513 # The options are a list of strings in this form optname:optvalue
514 # We are storing all the options in a dict so we can use it later when
515 # generating the images
516 for opt in options:
517 if ":" not in opt:
518 continue
519 key, value = opt.split(":")
520 # if value is a number, convert it to the appropriate type
521 if is_float(value):
522 value = float(value)
523 elif is_int(value):
524 value = int(value)
525 elif value.lower() in ["true", "false"]:
526 value = value.lower() == "true"
527 self.options[key] = value
528
529 # From options, extract if present "torch_dtype" and set it to the appropriate type
530 if "torch_dtype" in self.options:
531 if self.options["torch_dtype"] == "fp16":
532 torchType = torch.float16
533 elif self.options["torch_dtype"] == "bf16":
534 torchType = torch.bfloat16
535 elif self.options["torch_dtype"] == "fp32":
536 torchType = torch.float32
537 # remove it from options
538 del self.options["torch_dtype"]
539
540 print(f"Options: {self.options}", file=sys.stderr)
541
542 local = False
543 modelFile = request.Model
544
545 self.cfg_scale = 7
546 self.PipelineType = request.PipelineType
547
548 if request.CFGScale != 0:
549 self.cfg_scale = request.CFGScale
550
551 clipmodel = "Lykon/dreamshaper-8"
552 if request.CLIPModel != "":
553 clipmodel = request.CLIPModel
554 clipsubfolder = "text_encoder"

Callers

nothing calls this directly

Calls 7

_load_pipelineMethod · 0.95
get_schedulerFunction · 0.85
load_lora_weightsMethod · 0.80
appendMethod · 0.80
is_floatFunction · 0.70
is_intFunction · 0.70
toMethod · 0.45

Tested by

no test coverage detected