- Implemented backend model configuration mapping to training state. - Added auto-apply logic for default configurations when models are selected. - Introduced utilities for type conversion and validation within training configuration.
86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
import { authFetch } from "@/features/auth";
|
|
|
|
interface VisionCheckResponse {
|
|
model_name: string;
|
|
is_vision: boolean;
|
|
}
|
|
|
|
interface BackendTrainingDefaults {
|
|
max_seq_length?: number;
|
|
num_epochs?: number;
|
|
learning_rate?: number | string;
|
|
batch_size?: number;
|
|
gradient_accumulation_steps?: number;
|
|
warmup_steps?: number;
|
|
max_steps?: number;
|
|
save_steps?: number;
|
|
eval_steps?: number;
|
|
weight_decay?: number;
|
|
random_seed?: number;
|
|
packing?: boolean;
|
|
train_on_completions?: boolean;
|
|
gradient_checkpointing?: "none" | "true" | "unsloth";
|
|
}
|
|
|
|
interface BackendLoraDefaults {
|
|
lora_r?: number;
|
|
lora_alpha?: number;
|
|
lora_dropout?: number;
|
|
target_modules?: string[];
|
|
use_rslora?: boolean;
|
|
use_loftq?: boolean;
|
|
finetune_vision_layers?: boolean;
|
|
finetune_language_layers?: boolean;
|
|
finetune_attention_modules?: boolean;
|
|
finetune_mlp_modules?: boolean;
|
|
}
|
|
|
|
interface BackendLoggingDefaults {
|
|
enable_wandb?: boolean;
|
|
wandb_project?: string;
|
|
enable_tensorboard?: boolean;
|
|
tensorboard_dir?: string;
|
|
log_frequency?: number;
|
|
}
|
|
|
|
export interface BackendModelConfig {
|
|
training?: BackendTrainingDefaults;
|
|
lora?: BackendLoraDefaults;
|
|
logging?: BackendLoggingDefaults;
|
|
}
|
|
|
|
export interface ModelConfigResponse {
|
|
id: string;
|
|
model_name?: string | null;
|
|
config?: BackendModelConfig | null;
|
|
is_vision: boolean;
|
|
is_lora: boolean;
|
|
base_model?: string | null;
|
|
}
|
|
|
|
/**
|
|
* Check whether a model is a vision model by asking the backend.
|
|
* Calls GET /api/models/check-vision/{model_name}.
|
|
*/
|
|
export async function checkVisionModel(modelName: string): Promise<boolean> {
|
|
const encoded = encodeURIComponent(modelName);
|
|
const response = await authFetch(`/api/models/check-vision/${encoded}`);
|
|
if (!response.ok) {
|
|
// If the check fails (e.g. network error), default to non-vision
|
|
return false;
|
|
}
|
|
const data = (await response.json()) as VisionCheckResponse;
|
|
return data.is_vision;
|
|
}
|
|
|
|
export async function getModelConfig(
|
|
modelName: string,
|
|
signal?: AbortSignal,
|
|
): Promise<ModelConfigResponse> {
|
|
const encoded = encodeURIComponent(modelName);
|
|
const response = await authFetch(`/api/models/config/${encoded}`, { signal });
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to fetch model config (${response.status})`);
|
|
}
|
|
return (await response.json()) as ModelConfigResponse;
|
|
}
|