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

Method validate

python/ctranslate2/specs/model_spec.py:101–141  ·  view source on GitHub ↗

Verify that the required weights are set. Raises: ValueError: If a required weight is not set in the specification.

(self)

Source from the content-addressed store, hash-verified

99 """A layer specification declares the weights that should be set by the converters."""
100
101 def validate(self) -> None:
102 """Verify that the required weights are set.
103
104 Raises:
105 ValueError: If a required weight is not set in the specification.
106 """
107 unset_attributes = []
108
109 def _check(spec, name, value):
110 if value is None:
111 unset_attributes.append(name)
112 return
113
114 if isinstance(value, np.ndarray):
115 # float64 is not a supported type.
116 if value.dtype == np.float64:
117 value = value.astype(np.float32)
118 elif isinstance(value, float):
119 value = np.dtype("float32").type(value)
120 elif isinstance(value, bool):
121 # Convert bool to an integer type.
122 value = np.dtype("int8").type(value)
123 elif isinstance(value, str):
124 if value != OPTIONAL:
125 value = np.frombuffer(value.encode("utf-8"), dtype=np.int8)
126
127 if isinstance(value, np.ndarray) or isinstance(value, np.generic):
128 value = NumpyVariable(value)
129 elif torch_is_available and isinstance(value, torch.Tensor):
130 value = PyTorchVariable(value)
131
132 attr_name = _split_scope(name)[-1]
133 setattr(spec, attr_name, value)
134
135 self._visit(_check)
136
137 if unset_attributes:
138 raise ValueError(
139 "Some required model attributes are not set:\n\n%s"
140 % "\n".join(unset_attributes)
141 )
142
143 def variables(
144 self,

Callers 8

test_layer_spec_validateFunction · 0.45
test_layer_spec_optimizeFunction · 0.45
test_int8_quantizationFunction · 0.45
test_fp16_weightsFunction · 0.45
test_torch_variablesFunction · 0.45
validateMethod · 0.45
validateMethod · 0.45

Calls 2

_visitMethod · 0.95
joinMethod · 0.80

Tested by 6

test_layer_spec_validateFunction · 0.36
test_layer_spec_optimizeFunction · 0.36
test_int8_quantizationFunction · 0.36
test_fp16_weightsFunction · 0.36
test_torch_variablesFunction · 0.36