importVlQadBundle function

Future<void> importVlQadBundle(
  1. String language,
  2. String projector,
  3. String metadata,
  4. String output,
)

Imports into a portable bundle, retaining Q4 blocks and using the validated Q6_K-to-Q8 embedding/head adapter. Intermediate files are always removed.

Implementation

Future<void> importVlQadBundle(
  String language,
  String projector,
  String metadata,
  String output,
) async {
  if (Directory(output).existsSync()) throw StateError('output already exists');
  Directory(output).parent.createSync(recursive: true);
  final temp = Directory(output).parent.createTempSync('.dianoia-vl-qad-');
  try {
    if (!NativeKernels.isLoaded) NativeKernels.load(null);
    final vision = Directory('${temp.path}/vision')..createSync();
    final text = Directory('${temp.path}/text')..createSync();
    final backbone = '${temp.path}/language';
    final config = Lfm3VlConfig.load(metadata);
    for (final name in [
      'config.json',
      'processor_config.json',
      'tokenizer.json',
      'LICENSE',
    ]) {
      File('$metadata/$name').copySync('${vision.path}/$name');
    }
    importVlVisionGguf(projector, config, '${vision.path}/model.safetensors');
    final json =
        jsonDecode(File('$metadata/config.json').readAsStringSync()) as Map;
    File(
      '${text.path}/config.json',
    ).writeAsStringSync(jsonEncode(json['text_config']));
    File('$metadata/tokenizer.json').copySync('${text.path}/tokenizer.json');
    importGguf(language, text.path, backbone);
    writeVlBackboneIdentity(vision.path, backbone);
    await packVlBundle(
      vision.path,
      backbone,
      output,
      weights: WeightFormat.q4,
      useCacheEmbedding: true,
    );
  } finally {
    temp.deleteSync(recursive: true);
  }
}