MCPcopy Create free account
hub / github.com/TabbyML/tabby / _alias_variables

Method _alias_variables

python/ctranslate2/specs/model_spec.py:169–189  ·  view source on GitHub ↗

Find duplicate variables in spec and create aliases.

(self)

Source from the content-addressed store, hash-verified

167 return var
168
169 def _alias_variables(self):
170 """Find duplicate variables in spec and create aliases."""
171 # When a variable is duplicated, keep the version that comes first in
172 # the alphabetical order and alias the others.
173 variables = self.variables(ordered=True)
174 for name, value in reversed(variables):
175 for other_name, other_value in variables:
176 if name == other_name:
177 break
178 # Because variables can be transformed on load (e.g. transposed),
179 # we use an element-wise equality check.
180 scope, attr_name = _parent_scope(name)
181 if (
182 not value.is_scalar()
183 and value.equal(other_value)
184 and attr_name not in SKIP_CREATING_ALIAS
185 ):
186 # Replace variable value by the alias name.
187 spec = index_spec(self, scope)
188 setattr(spec, attr_name, other_name)
189 break
190
191 def _quantize(self, quantization):
192 """Possibly quantizes the variable of the layer."""

Callers 1

optimizeMethod · 0.95

Calls 5

variablesMethod · 0.95
_parent_scopeFunction · 0.85
index_specFunction · 0.85
equalMethod · 0.80
is_scalarMethod · 0.45

Tested by

no test coverage detected