unload method

Future<void> unload()

Unload the currently-loaded diffusion model.

Implementation

Future<void> unload() async {
  _ensureInitialized();

  final modelId = currentModelId ??
      (await RunAnywhereModelLifecycle.shared.current(
        model_pb.CurrentModelRequest(category: _diffusionCategory),
      ))
          .modelId;
  if (modelId.isEmpty) return;

  final result = await RunAnywhereModelLifecycle.shared.unload(
    model_pb.ModelUnloadRequest(
      modelId: modelId,
      category: _diffusionCategory,
    ),
  );
  if (result.hasError()) {
    throw SDKException.invalidState(
      result.error.message.isNotEmpty
          ? result.error.message
          : 'Diffusion lifecycle unload failed',
    );
  }
}