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

Method variables

python/ctranslate2/specs/model_spec.py:143–167  ·  view source on GitHub ↗

Recursively returns the weights from this layer and its children. Arguments: prefix: Prefix to prepend to all variable names. ordered: If set, an ordered list is returned instead. Returns: Dictionary mapping variables name to value.

(
        self,
        prefix: str = "",
        ordered: bool = False,
    )

Source from the content-addressed store, hash-verified

141 )
142
143 def variables(
144 self,
145 prefix: str = "",
146 ordered: bool = False,
147 ) -> Dict[str, np.ndarray]:
148 """Recursively returns the weights from this layer and its children.
149
150 Arguments:
151 prefix: Prefix to prepend to all variable names.
152 ordered: If set, an ordered list is returned instead.
153
154 Returns:
155 Dictionary mapping variables name to value.
156 """
157 var = {}
158
159 def _register_var(spec, name, value):
160 if isinstance(value, str) and value == OPTIONAL:
161 return
162 var[_join_scope(prefix, name)] = value
163
164 self._visit(_register_var)
165 if ordered:
166 return list(sorted(var.items(), key=lambda x: x[0]))
167 return var
168
169 def _alias_variables(self):
170 """Find duplicate variables in spec and create aliases."""

Callers 3

_alias_variablesMethod · 0.95
test_torch_variablesFunction · 0.80
_serializeMethod · 0.80

Calls 1

_visitMethod · 0.95

Tested by 1

test_torch_variablesFunction · 0.64