From a68da643f139d01b1b76c0de0bcfb4a011253959 Mon Sep 17 00:00:00 2001 From: QualiaRain <44004657+QualiaRain@users.noreply.github.com> Date: Sat, 13 Jun 2026 00:22:24 -0400 Subject: [PATCH] fix(runtime): capture bias dtype cast, coerce env seq-len to int, init pipeline before use sd_hijack_accelerate.py: bias.to(weight.dtype) discarded its result (Tensor.to is not in-place), so the conv still received the mismatched bias. sd_hijack_te.py: os.environ.get returns a str when MAX_SEQUENCE_LENGTH is set, so max(int, str) raised TypeError (uncaught, before the try); coerce with int(). sd_detect.py: pipeline was referenced in 'if callable(pipeline)' but only assigned when cls is not None, raising UnboundLocalError for a model_index.json without _class_name. Co-Authored-By: Claude --- modules/sd_detect.py | 1 + modules/sd_hijack_accelerate.py | 2 +- modules/sd_hijack_te.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/sd_detect.py b/modules/sd_detect.py index f87d7ae25..045d46a28 100644 --- a/modules/sd_detect.py +++ b/modules/sd_detect.py @@ -187,6 +187,7 @@ def guess_by_diffusers(fn, current_guess): cls = index.get('_class_name', None) if isinstance(cls, list): cls = cls[-1] + pipeline = None if cls is not None: pipeline = getattr(diffusers, cls, None) if pipeline is None: diff --git a/modules/sd_hijack_accelerate.py b/modules/sd_hijack_accelerate.py index 0467c536b..45e892d1e 100644 --- a/modules/sd_hijack_accelerate.py +++ b/modules/sd_hijack_accelerate.py @@ -84,7 +84,7 @@ def torch_conv_forward(self, input, weight, bias): # pylint: disable=redefined-b if self.padding_mode != 'zeros': return F.conv2d(F.pad(input, self._reversed_padding_repeated_twice, mode=self.padding_mode), weight, bias, self.stride, _pair(0), self.dilation, self.groups) # pylint: disable=protected-access if weight.dtype != bias.dtype: - bias.to(weight.dtype) + bias = bias.to(weight.dtype) return F.conv2d(input, weight, bias, self.stride, self.padding, self.dilation, self.groups) def hijack_torch_conv(): diff --git a/modules/sd_hijack_te.py b/modules/sd_hijack_te.py index e947ec4f2..c1163eabb 100644 --- a/modules/sd_hijack_te.py +++ b/modules/sd_hijack_te.py @@ -8,7 +8,7 @@ def hijack_encode_prompt(*args, **kwargs): jobid = shared.state.begin('TE Encode') t0 = time.time() if 'max_sequence_length' in kwargs and kwargs['max_sequence_length'] is not None: - kwargs['max_sequence_length'] = max(kwargs['max_sequence_length'], os.environ.get('MAX_SEQUENCE_LENGTH', 256)) + kwargs['max_sequence_length'] = max(kwargs['max_sequence_length'], int(os.environ.get('MAX_SEQUENCE_LENGTH', 256))) res = None try: args_copy = list(args)