diff --git a/test/README.md b/test/README.md index fdb79145..70b65934 100644 --- a/test/README.md +++ b/test/README.md @@ -13,7 +13,7 @@ sezione "Sicurezza". | `file_handle_pool_test.cpp` | pool dei flussi aperti sui file modello: riuso, file modificato o sostituito, flussi in errore, limiti, uso concorrente (con ASan/UBSan e TSan) | vedi intestazione del file | | `model_loader_latency_test.cpp` | attesa alla fine di `ModelLoader::load_tensors`: un caricamento di pochi tensori già pronti torna in meno di 100 ms (prima aspettava un intero intervallo di 200 ms a ogni caricamento, e i pesi in streaming ne fanno decine per ogni passo), dati letti esatti, errore di un tensore segnalato subito. Scrive da solo un piccolo file safetensors: serve la libreria compilata, nessuna GPU né modello | vedi intestazione del file | | `profile_test.cpp` | profili di risorse (`--profile`): scelta automatica da dimensione del modello e memoria (anche sommando la memoria di più GPU), ordine dei livelli, opzioni esplicite che vincono sul profilo | vedi intestazione del file | -| `backend_fit_plan_test.cpp` | pianificatore multi-GPU dell'auto-fit (`--multi-gpu auto\|on\|off`) con GPU simulate: quale modulo va su quale GPU, quando il modello si divide per blocchi, nessun device riceve più pesi del suo budget, i moduli assegnati dall'utente non si muovono. Con più backend installati insieme (CUDA e Vulkan): la stessa scheda vista da due backend conta una volta sola, una GPU integrata non diventa la scheda principale finché una scheda ha memoria libera e la sua memoria condivisa (la RAM) non ospita pesi (include `src/core/backend_fit.cpp`, quindi serve la libreria compilata; nessuna GPU né modello) | vedi intestazione del file | +| `backend_fit_plan_test.cpp` | pianificatore multi-GPU dell'auto-fit (`--multi-gpu auto\|on\|off`) con GPU simulate: quale modulo va su quale GPU, quando il modello si divide per blocchi, nessun device riceve più pesi del suo budget, i moduli assegnati dall'utente non si muovono. Con più backend installati insieme (CUDA e Vulkan): la stessa scheda vista da due backend conta una volta sola, una GPU integrata non diventa la scheda principale finché una scheda ha memoria libera e la sua memoria condivisa (la RAM) non ospita pesi; gli avvisi dopo il piano: `--backend vulkan0` su una scheda che CUDA elenca come CUDA0, e pesi lasciati su disco che vengono riletti a ogni passo (include `src/core/backend_fit.cpp`, quindi serve la libreria compilata; nessuna GPU né modello) | vedi intestazione del file | | `package_windows_cuda_vulkan_test.sh` | script che assembla lo zip Windows con CUDA e Vulkan insieme (`scripts/package_windows_cuda_vulkan.sh`, passo del job `release` di `build.yml`) con zip finti che hanno i nomi di quelli veri: pacchetto in una cartella sola con tutti i file (programmi e `stable-diffusion.dll` dallo zip CUDA, solo `ggml-vulkan.dll` dallo zip Vulkan, DLL di CUDA, `LEGGIMI.txt`), avviso se `ggml-base.dll` o `ggml.dll` hanno dimensioni diverse, rifiuto di uno zip mancante o doppio, di zip di commit diversi, di moduli o DLL mancanti, di file con lo stesso nome in due zip e di un `LEGGIMI.txt` già presente, due esecuzioni nella stessa cartella. Servono `zip` e `unzip`; nessuna build, GPU o modello | `./test/package_windows_cuda_vulkan_test.sh` (meno di un secondo) | | `server_recovery_test.cpp` | custode del contesto del server (`examples/server/recovery.*`): scala dei profili, discesa su memoria insufficiente, risalita dopo una pausa, ricarica dopo un errore, risposte HTTP 503/400/500 con `Retry-After`, uso da più thread. Annullamento di una generazione in corso: lo stop raggiunge solo il job che lo ha chiesto, un job annullato prima di partire non genera nulla, non costa nessuna ricarica del modello e non conta come errore. Non serve nessun modello: libreria e orologio sono simulati (con ASan/UBSan e TSan) | vedi intestazione del file | | `server_cancel_e2e.py` | annullamento di un job in corso su un vero `sd-server` (serve un modello qualsiasi, su qualunque backend): job fermato, richiesta ripetuta, job in coda, `?wait=0`, POST senza corpo né `Content-Length` (come `curl -X POST`: risposta subito, non dopo 5 secondi), richiesta sincrona in attesa che poi completa, job già finito, id sconosciuto, `wait` non valido, contatori di `/sdcpp/v1/health` e log senza righe di errore | `python3 test/server_cancel_e2e.py --server build/bin/sd-server --model ` | diff --git a/test/backend_fit_plan_test.cpp b/test/backend_fit_plan_test.cpp index 60c3dcf3..cf977bbc 100644 --- a/test/backend_fit_plan_test.cpp +++ b/test/backend_fit_plan_test.cpp @@ -386,6 +386,92 @@ static void check_mixed_backends() { } } +static bool has(const std::string& text, const char* part) { + return text.find(part) != std::string::npos; +} + +// The two warnings derive_backend_specs logs after the plan: a module run on a listing of a GPU that another backend +// already provides, and weights that stream from disk. +static void check_plan_warnings() { + const char* const card_id = "0000:01:00.0"; + const Runtime on_cuda{"CUDA0", {0}}; + const Runtime on_vulkan{"Vulkan0", {1}}; + + { + std::vector card = {with_id(make_gpu("CUDA0", "CUDA", 8), card_id), with_id(make_gpu("Vulkan0", "Vulkan", 8), card_id)}; + mark_shadowed_devices(card); + const std::vector components = make_components(4.8, 1.5, 0.15); + + const Plan forced = compute_plan(components, card, 16 * GiB, std::vector(3, on_vulkan)); + const std::vector warnings = shadowed_runtime_warnings(forced, card); + CHECK(warnings.size() == 1 && has(warnings[0], "Vulkan0 is the same GPU as CUDA0") && has(warnings[0], "name CUDA0 in --backend"), + "--backend vulkan0 on a card that CUDA lists as CUDA0: one warning that names both and says what to pass instead"); + + const std::vector mixed = {on_cuda, on_vulkan, on_vulkan}; + CHECK(shadowed_runtime_warnings(compute_plan(components, card, 16 * GiB, mixed), card).size() == 1, + "and still one warning when several modules run on that listing"); + CHECK(shadowed_runtime_warnings(compute_plan(components, card, 16 * GiB, std::vector(3, on_cuda)), card).empty(), + "nothing is said when the modules run on the listing the automatic choice makes"); + + std::vector unknown = {make_gpu("CUDA0", "CUDA", 8), make_gpu("Vulkan0", "Vulkan", 8)}; + mark_shadowed_devices(unknown); + CHECK(shadowed_runtime_warnings(compute_plan(components, unknown, 16 * GiB, std::vector(3, on_vulkan)), unknown).empty(), + "listings that report no PCI id cannot be told apart from two cards, so nothing is claimed about them"); + } + + { + std::vector rig = {with_id(make_gpu("CUDA0", "CUDA", 12), "0000:01:00.0"), with_id(make_gpu("CUDA1", "CUDA", 12), "0000:02:00.0"), + with_id(make_gpu("Vulkan0", "Vulkan", 12), "0000:01:00.0"), with_id(make_gpu("Vulkan1", "Vulkan", 12), "0000:02:00.0")}; + mark_shadowed_devices(rig); + const std::vector components = make_components(16, 2, 0.3); + + const std::vector on_cuda_pair(3, Runtime{"CUDA0&CUDA1", {0, 1}}); + CHECK(shadowed_runtime_warnings(compute_plan(components, rig, 0, on_cuda_pair), rig).empty(), "two cards each listed twice: the CUDA pair is not warned about"); + + const std::vector on_vulkan_pair(3, Runtime{"Vulkan0&Vulkan1", {2, 3}}); + const std::vector warnings = shadowed_runtime_warnings(compute_plan(components, rig, 0, on_vulkan_pair), rig); + CHECK(warnings.size() == 2 && has(warnings[0], "Vulkan0 is the same GPU as CUDA0") && has(warnings[1], "Vulkan1 is the same GPU as CUDA1"), + "and the Vulkan pair gets one warning per card"); + } + + { + std::vector twice = {with_id(make_gpu("Vulkan0", "Vulkan", 8), card_id), with_id(make_gpu("Vulkan1", "Vulkan", 8), card_id)}; + mark_shadowed_devices(twice); + const std::vector warnings = + shadowed_runtime_warnings(compute_plan(make_components(4.8, 1.5, 0.15), twice, 0, std::vector(3, Runtime{"Vulkan1", {1}})), twice); + CHECK(warnings.size() == 1 && has(warnings[0], "Vulkan1 is the same GPU as Vulkan0") && !has(warnings[0], "generic graphics API"), + "two listings of the same backend: the warning names the owner but does not claim the other backend is slower"); + } + + { + // Pony-sized weights on a 5 GiB card with 3 GiB of RAM budget: the diffusion model fits neither. + const std::vector card = {make_gpu("CUDA0", "CUDA", 5)}; + const std::vector components = make_components(4.8, 1.5, 0.15); + const std::vector start = {on_cuda, Runtime{"CPU", {}}, on_cuda}; + const Plan plan = compute_plan(components, card, 3 * GiB, start); + CHECK(plan.decisions[0].params_location == ParamsLocation::DISK, "setup: the diffusion weights are left on disk"); + + const std::string warning = disk_streaming_warning(plan, components, 4 * GiB, 3 * GiB); + CHECK(has(warning, "weights of DiT (") && !has(warning, "Conditioner") && !has(warning, "VAE") && + has(warning, (std::to_string(components[0].params_bytes / MiB) + " MiB").c_str()), + "weights on disk: the warning names the module that streams and how much it is"); + CHECK(has(warning, "the diffusion model at every sampling step") && has(warning, "free RAM is 4096 MiB") && has(warning, "budget for weights 3072 MiB") && + has(warning, "--type"), + "it says that the diffusion model is read at every step, how much RAM there is, and what helps"); + CHECK(disk_streaming_warning(plan, components, -1, 0).empty(), "an unknown amount of RAM gives no warning, since print_plan already says it is unknown"); + + const Plan resident_plan = compute_plan(components, card, 64 * GiB, start); + CHECK(resident_plan.decisions[0].params_location == ParamsLocation::CPU && disk_streaming_warning(resident_plan, components, 64 * GiB, 60 * GiB).empty(), + "nothing is said when the weights wait in RAM"); + + Plan vae_only; + vae_only.decisions.assign(3, Decision{ParamsLocation::CPU}); + vae_only.decisions[2].params_location = ParamsLocation::DISK; + const std::string vae_warning = disk_streaming_warning(vae_only, components, 4 * GiB, 1 * GiB); + CHECK(has(vae_warning, "weights of VAE (") && !has(vae_warning, "sampling step"), "a module other than the diffusion model is not said to be read at every sampling step"); + } +} + // Random machines with a card listed by one or two backends and sometimes an integrated GPU, in a random order: // whatever the plan, nothing is placed on a listing that is not the GPU's own. static void check_random_mixed_backends() { @@ -659,6 +745,7 @@ int main() { } check_mixed_backends(); + check_plan_warnings(); check_random_machines(); check_random_mixed_backends();