validate method

void validate()

Validates the parameter combination. Throws LlamaArgumentException when a value is out of range or the combination is incompatible with llama.cpp (a non-F16 KV cache requires flashAttention != disabled), or when device contradicts another field:

LlamaEngine model loads call it before any download or native call, so callers don't have to remember it; call it directly to validate a ModelParams up front.

Implementation

void validate() {
  _validateDevice();
  if (liteRtLmPrefillChunkSize != null && liteRtLmPrefillChunkSize! <= 0) {
    throw _invalid(
      'liteRtLmPrefillChunkSize',
      liteRtLmPrefillChunkSize,
      'must be positive when provided',
    );
  }
  if (liteRtLmDispatchLibDir != null &&
      liteRtLmDispatchLibDir!.trim().isEmpty) {
    throw _invalid(
      'liteRtLmDispatchLibDir',
      liteRtLmDispatchLibDir,
      'must be non-empty when provided',
    );
  }
  if (liteRtLmCacheDir != null && liteRtLmCacheDir!.trim().isEmpty) {
    throw _invalid(
      'liteRtLmCacheDir',
      liteRtLmCacheDir,
      'must be non-empty when provided',
    );
  }
  if (liteRtLmMaxProgramCacheBytes != null &&
      liteRtLmMaxProgramCacheBytes! < unlimitedLiteRtLmProgramCacheBytes) {
    throw _invalid(
      'liteRtLmMaxProgramCacheBytes',
      liteRtLmMaxProgramCacheBytes,
      'must be non-negative, or '
          'ModelParams.unlimitedLiteRtLmProgramCacheBytes (-1) to keep '
          'every program cache',
    );
  }
  if (speculativeRollbackTokenMax < 0) {
    throw _invalid(
      'speculativeRollbackTokenMax',
      speculativeRollbackTokenMax,
      'must be non-negative',
    );
  }
  if ((cacheTypeK != KvCacheType.f16 || cacheTypeV != KvCacheType.f16) &&
      flashAttention == FlashAttention.disabled) {
    throw LlamaArgumentException(
      'Non-F16 KV cache (cacheTypeK=$cacheTypeK, cacheTypeV=$cacheTypeV) '
      'requires flashAttention != disabled. Either set flashAttention to '
      'auto/enabled or use KvCacheType.f16 for both.',
    );
  }
}