load static method

ControlVector load(
  1. String path, {
  2. ControlMode mode = ControlMode.add,
  3. double scale = 1.0,
  4. int firstLayer = 0,
  5. int? lastLayer,
})

Reads the directions of a control-vector file: safetensors as save writes it, or llama.cpp's GGUF (which needs the native kernels, for the mapping). Every tensor must be an F32 vector named direction.<l>.

Implementation

static ControlVector load(
  String path, {
  ControlMode mode = ControlMode.add,
  double scale = 1.0,
  int firstLayer = 0,
  int? lastLayer,
}) {
  final raw = _isGguf(path) ? _readGguf(path) : _readSafetensors(path);
  if (raw.isEmpty) throw FormatException('$path holds no directions');
  final sizes = {for (final d in raw.values) d.length};
  if (sizes.length != 1) {
    throw FormatException('$path has directions of sizes $sizes');
  }
  return ControlVector(
    raw,
    hiddenSize: sizes.single,
    mode: mode,
    scale: scale,
    firstLayer: firstLayer,
    lastLayer: lastLayer,
  );
}