From 7b6f7ab3d3c8e1c8d77166a383f76052659627bb Mon Sep 17 00:00:00 2001 From: ale18V Date: Thu, 12 Nov 2026 16:56:05 +0100 Subject: [PATCH 1/2] feat: configure aggregator strategy and params in task creation UI --- webapp/cypress/e2e/task-creation.cy.ts | 148 +++++++++++++ .../task_creation_form/TaskCreationForm.vue | 201 ++++++++---------- 2 files changed, 231 insertions(+), 118 deletions(-) diff --git a/webapp/cypress/e2e/task-creation.cy.ts b/webapp/cypress/e2e/task-creation.cy.ts index a011d9e7f..e950fd970 100644 --- a/webapp/cypress/e2e/task-creation.cy.ts +++ b/webapp/cypress/e2e/task-creation.cy.ts @@ -92,6 +92,154 @@ it("submits with tabular task", () => { } satisfies Task<"tabular", "federated">); }); +for (const aggregation of [ + { + scheme: "federated", + aggregationStrategy: "byzantine", + aggregationParams: { clippingRadius: 2.5, maxIterations: 3, beta: 0.8 }, + }, + { + scheme: "decentralized", + aggregationStrategy: "secure", + aggregationParams: { maxShareValue: 250 }, + maxConnectionRetry: 3, + maxPeerConnectionTime: 60_000, + maxModelSyncTime: 30_000, + }, +] as const) { + it(`submits with custom aggregation parameters (${aggregation.aggregationStrategy})`, () => { + cy.intercept( + { hostname: "server", pathname: "tasks", method: "POST" }, + { statusCode: 200 }, + ).as("posted"); + + cy.visit("/create"); + + cy.get("form").should("be.visible"); + + cy.get("input[name='id']").type("aggregation-task"); + cy.get("select[name='dataType']").select("tabular"); + + cy.get("input[name='displayInformation.title']").type("aggregation title"); + cy.get("input[name='displayInformation.summary.preview']").type("preview"); + cy.get("textarea[name='displayInformation.summary.overview']").type( + "overview", + ); + cy.contains("Example tabular data").within(() => { + cy.contains("add example").click(); + cy.get("input[name='displayInformation.dataExample[0].name']").type( + "name", + ); + cy.get("input[name='displayInformation.dataExample[0].data']").type( + "data", + ); + }); + + cy.get("select[name='trainingInformation.scheme']").select("decentralized"); + cy.get("select[name='trainingInformation.aggregationStrategy']").select( + "secure", + ); + cy.get("select[name='trainingInformation.scheme']").select("federated"); + cy.get("select[name='trainingInformation.aggregationStrategy']").should( + "have.value", + "mean", + ); + cy.get( + "select[name='trainingInformation.aggregationStrategy'] option[value='secure']", + ).should("not.exist"); + cy.get("select[name='trainingInformation.aggregationStrategy']").select( + "byzantine", + ); + cy.get( + "input[name='trainingInformation.aggregationParams.clippingRadius']", + ).type("2.5"); + cy.get("select[name='trainingInformation.scheme']").select("decentralized"); + cy.get("select[name='trainingInformation.aggregationStrategy']").select( + "secure", + ); + cy.get( + "input[name='trainingInformation.aggregationParams.maxShareValue']", + ).type("250"); + cy.get("select[name='trainingInformation.scheme']").select( + aggregation.scheme, + ); + cy.get("select[name='trainingInformation.aggregationStrategy']").select( + aggregation.aggregationStrategy, + ); + for (const [key, value] of Object.entries(aggregation.aggregationParams)) { + cy.get( + `input[name='trainingInformation.aggregationParams.${key}']`, + ).clear(); + cy.get(`input[name='trainingInformation.aggregationParams.${key}']`).type( + String(value), + ); + } + + cy.get("input[name='trainingInformation.epochs']").type("10"); + cy.get("input[name='trainingInformation.batchSize']").type("5"); + cy.get("input[name='trainingInformation.roundDuration']").type("2"); + cy.get("input[name='trainingInformation.validationSplit']").type("0"); + cy.get("input[name='trainingInformation.minNbOfParticipants']").type("2"); + cy.contains("Input columns names").within(() => { + cy.get("input[name='trainingInformation.inputColumns[0]']").type("input"); + }); + cy.get("input[name='trainingInformation.outputColumn']").type("output"); + + const model = tf.sequential({ + layers: [ + tf.layers.conv2d({ + inputShape: [32, 32, 3], + kernelSize: 3, + filters: 16, + activation: "relu", + }), + ], + }); + model.compile({ loss: "hinge", optimizer: "sgd" }); + cy.wrap(getArtifacts(model)) + .then((artifacts) => JSON.stringify(artifacts)) + .then((json) => new TextEncoder().encode(json)) + .then((raw) => + cy.get("input[type='file']").selectFile(new Uint8Array(raw), { + force: true, + }), + ); + cy.get("select[name='model.loss']").select("hinge"); + cy.get("select[name='model.optimizer.name']").select("sgd"); + cy.get("input[name='model.optimizer.learningRate']").type("0.01"); + + cy.get("button[type='submit']").click(); + + cy.wait("@posted") + .its("request.body.task") + .then(deserializeTaskFromJSON) + .should("deep.equal", { + id: "aggregation-task", + dataType: "tabular", + displayInformation: { + title: "aggregation title", + summary: { + preview: "preview", + overview: "overview", + }, + dataExample: [{ name: "name", data: "data" }], + }, + trainingInformation: { + ...aggregation, + epochs: 10, + batchSize: 5, + roundDuration: 2, + validationSplit: 0, + minNbOfParticipants: 2, + inputColumns: ["input"], + categoricalColumns: {}, + outputColumn: "output", + tensorBackend: "tfjs", + }, + }); + }); +} + async function getArtifacts( model: tf.LayersModel, ): Promise { diff --git a/webapp/src/components/task_creation_form/TaskCreationForm.vue b/webapp/src/components/task_creation_form/TaskCreationForm.vue index df4bc6f69..a8344560b 100644 --- a/webapp/src/components/task_creation_form/TaskCreationForm.vue +++ b/webapp/src/components/task_creation_form/TaskCreationForm.vue @@ -420,17 +420,59 @@ + + + +
+ + + + + + + + + + + +
- - - - - - - - - - - - - - -
- - - -
-
@@ -766,6 +746,10 @@ import { Task, Tokenizer, TrainingInformation, + aggregationConfigSchema, + FEDERATED_AGGREGATION_STRATEGIES, + DECENTRALIZED_AGGREGATION_STRATEGIES, + type AggregationStrategy, type DataType, type Network, } from "@epfml/discojs"; @@ -789,9 +773,8 @@ const { tasks } = storeToRefs(useTasksStore()); const dataType = ref("image"); const scheme = ref("federated"); -const aggregationStrategy = ref("mean"); +const aggregationStrategy = ref("mean"); const differentialPrivacy = ref(false); -const weightClipping = ref(false); const form = useTemplateRef("form"); @@ -812,8 +795,16 @@ watch([dataType, form], ([dataType, form]) => { watch([scheme, form], ([scheme, form]) => { if (form === null) return; - if (scheme !== "decentralized") + if (scheme === "local") { form.setFieldValue("trainingInformation.aggregationStrategy", "mean"); + } else if (scheme === "federated" && aggregationStrategy.value === "secure") { + form.setFieldValue("trainingInformation.aggregationStrategy", "mean"); + } +}); + +watch(aggregationStrategy, () => { + if (form.value === null) return; + form.value.setFieldValue("trainingInformation.aggregationParams", undefined); }); // warn user on page content loss @@ -848,62 +839,35 @@ const nonLocalNetworkSchema = z minNbOfParticipants: z.number().positive().int(), }) .and( - z.union([ - z.object({ - aggregationStrategy: z.literal("mean"), - }), - z.object({ - aggregationStrategy: z.literal("byzantine"), - privacy: privacySchema.and( - z - .object({ - byzantineFaultTolerance: z - .object({ - clippingRadius: z.number().positive().default(1.0), - maxIterations: z.number().int().positive().default(1), - beta: z.number().min(0).max(1).default(0.9), - }) - .optional(), - }) - .transform((arg, ctx) => { - if (!weightClipping.value) return undefined; - - function addUndefIssue(field?: string[]): void { - const path = field !== undefined ? field : undefined; - ctx.addIssue({ - code: "custom", - message: "Required", - path, - }); - } - - if (arg === undefined) { - addUndefIssue(); - return z.NEVER; - } - const { byzantineFaultTolerance } = arg; - if (byzantineFaultTolerance === undefined) { - addUndefIssue(["byzantineFaultTolerance"]); - return z.NEVER; - } - - return { byzantineFaultTolerance }; - }) - .optional(), - ), - }), - z.object({ - aggregationStrategy: z.literal("secure"), - maxShareValue: z.number().positive().int(), - }), - ]), + z.preprocess((val) => { + if ( + typeof val === "object" && + val !== null && + "aggregationParams" in val && + typeof val.aggregationParams === "object" && + val.aggregationParams !== null + ) { + const cleanedParams = Object.fromEntries( + Object.entries(val.aggregationParams as Record).map( + ([k, v]) => [ + k, + v === "" || (typeof v === "number" && Number.isNaN(v)) + ? undefined + : v, + ], + ), + ); + return { ...val, aggregationParams: cleanedParams }; + } + return val; + }, aggregationConfigSchema), ); const trainingInformationNetworks = z.union([ z .object({ scheme: z.literal("decentralized"), - aggregationStrategy: z.literal(["byzantine", "mean", "secure"]), + aggregationStrategy: z.enum(DECENTRALIZED_AGGREGATION_STRATEGIES), // Maximum number of retries for connection failures maxConnectionRetry: z.number().nonnegative().int().default(3), @@ -919,12 +883,13 @@ const trainingInformationNetworks = z.union([ z .object({ scheme: z.literal("federated"), - aggregationStrategy: z.literal(["byzantine", "mean"]), + aggregationStrategy: z.enum(FEDERATED_AGGREGATION_STRATEGIES), }) .and(nonLocalNetworkSchema), z.object({ scheme: z.literal("local"), aggregationStrategy: z.literal("mean"), + aggregationParams: z.undefined().optional(), }), ]); From 09b35ff61a87a2f7926f6d44da7ccea3b6e30fae Mon Sep 17 00:00:00 2001 From: ale18V Date: Tue, 24 Nov 2026 17:53:02 +0100 Subject: [PATCH 2/2] fix(webapp): address PR #1291 review feedback on aggregator params --- webapp/cypress/e2e/task-creation.cy.ts | 314 +++++++++++------- .../task_creation_form/TaskCreationForm.vue | 8 +- 2 files changed, 205 insertions(+), 117 deletions(-) diff --git a/webapp/cypress/e2e/task-creation.cy.ts b/webapp/cypress/e2e/task-creation.cy.ts index e950fd970..1bb095ba8 100644 --- a/webapp/cypress/e2e/task-creation.cy.ts +++ b/webapp/cypress/e2e/task-creation.cy.ts @@ -3,64 +3,10 @@ import { deserializeTaskFromJSON, type Task } from "@epfml/discojs"; import * as tf from "@tensorflow/tfjs"; it("submits with tabular task", () => { - cy.intercept( - { hostname: "server", pathname: "tasks", method: "POST" }, - { statusCode: 200 }, - ).as("posted"); - - cy.visit("/create"); - - cy.get("form").should("be.visible"); // Wait for the form to be fully loaded - - cy.get("input[name='id']").type("id"); - cy.get("select[name='dataType']").select("tabular"); - - cy.get("input[name='displayInformation.title']").type("simple"); - cy.get("input[name='displayInformation.summary.preview']").type("preview"); - cy.get("textarea[name='displayInformation.summary.overview']").type( - "overview", - ); - cy.contains("Example tabular data").within(() => { - cy.contains("add example").click(); - cy.get("input[name='displayInformation.dataExample[0].name']").type("name"); - cy.get("input[name='displayInformation.dataExample[0].data']").type("data"); - }); + visitAndFillTabularTaskBasics("id", "simple"); cy.get("select[name='trainingInformation.scheme']").select("federated"); - cy.get("input[name='trainingInformation.epochs']").type("10"); - cy.get("input[name='trainingInformation.batchSize']").type("5"); - cy.get("input[name='trainingInformation.roundDuration']").type("2"); - cy.get("input[name='trainingInformation.validationSplit']").type("0"); - cy.get("input[name='trainingInformation.minNbOfParticipants']").type("2"); - cy.contains("Input columns names").within(() => { - cy.get("input[name='trainingInformation.inputColumns[0]']").type("input"); - }); - cy.get("input[name='trainingInformation.outputColumn']").type("output"); - - const model = tf.sequential({ - layers: [ - tf.layers.conv2d({ - inputShape: [32, 32, 3], - kernelSize: 3, - filters: 16, - activation: "relu", - }), - ], - }); - model.compile({ loss: "hinge", optimizer: "sgd" }); - cy.wrap(getArtifacts(model)) - .then((artifacts) => JSON.stringify(artifacts)) - .then((json) => new TextEncoder().encode(json)) - .then((raw) => - cy.get("input[type='file']").selectFile(new Uint8Array(raw), { - force: true, // input is hidden - }), - ); - cy.get("select[name='model.loss']").select("hinge"); - cy.get("select[name='model.optimizer.name']").select("sgd"); - cy.get("input[name='model.optimizer.learningRate']").type("0.01"); - - cy.get("button[type='submit']").click(); + fillRemainingTabularFieldsAndSubmit(); cy.wait("@posted") .its("request.body.task") @@ -108,32 +54,7 @@ for (const aggregation of [ }, ] as const) { it(`submits with custom aggregation parameters (${aggregation.aggregationStrategy})`, () => { - cy.intercept( - { hostname: "server", pathname: "tasks", method: "POST" }, - { statusCode: 200 }, - ).as("posted"); - - cy.visit("/create"); - - cy.get("form").should("be.visible"); - - cy.get("input[name='id']").type("aggregation-task"); - cy.get("select[name='dataType']").select("tabular"); - - cy.get("input[name='displayInformation.title']").type("aggregation title"); - cy.get("input[name='displayInformation.summary.preview']").type("preview"); - cy.get("textarea[name='displayInformation.summary.overview']").type( - "overview", - ); - cy.contains("Example tabular data").within(() => { - cy.contains("add example").click(); - cy.get("input[name='displayInformation.dataExample[0].name']").type( - "name", - ); - cy.get("input[name='displayInformation.dataExample[0].data']").type( - "data", - ); - }); + visitAndFillTabularTaskBasics("aggregation-task", "aggregation title"); cy.get("select[name='trainingInformation.scheme']").select("decentralized"); cy.get("select[name='trainingInformation.aggregationStrategy']").select( @@ -175,40 +96,7 @@ for (const aggregation of [ ); } - cy.get("input[name='trainingInformation.epochs']").type("10"); - cy.get("input[name='trainingInformation.batchSize']").type("5"); - cy.get("input[name='trainingInformation.roundDuration']").type("2"); - cy.get("input[name='trainingInformation.validationSplit']").type("0"); - cy.get("input[name='trainingInformation.minNbOfParticipants']").type("2"); - cy.contains("Input columns names").within(() => { - cy.get("input[name='trainingInformation.inputColumns[0]']").type("input"); - }); - cy.get("input[name='trainingInformation.outputColumn']").type("output"); - - const model = tf.sequential({ - layers: [ - tf.layers.conv2d({ - inputShape: [32, 32, 3], - kernelSize: 3, - filters: 16, - activation: "relu", - }), - ], - }); - model.compile({ loss: "hinge", optimizer: "sgd" }); - cy.wrap(getArtifacts(model)) - .then((artifacts) => JSON.stringify(artifacts)) - .then((json) => new TextEncoder().encode(json)) - .then((raw) => - cy.get("input[type='file']").selectFile(new Uint8Array(raw), { - force: true, - }), - ); - cy.get("select[name='model.loss']").select("hinge"); - cy.get("select[name='model.optimizer.name']").select("sgd"); - cy.get("input[name='model.optimizer.learningRate']").type("0.01"); - - cy.get("button[type='submit']").click(); + fillRemainingTabularFieldsAndSubmit(); cy.wait("@posted") .its("request.body.task") @@ -240,6 +128,200 @@ for (const aggregation of [ }); } +it("does not submit aggregationParams when switching from byzantine to mean", () => { + visitAndFillTabularTaskBasics( + "aggregation-reset-task", + "aggregation reset title", + ); + + cy.get("select[name='trainingInformation.scheme']").select("federated"); + cy.get("select[name='trainingInformation.aggregationStrategy']").select( + "byzantine", + ); + cy.get( + "input[name='trainingInformation.aggregationParams.clippingRadius']", + ).type("2.5"); + cy.get( + "input[name='trainingInformation.aggregationParams.maxIterations']", + ).type("3"); + cy.get("input[name='trainingInformation.aggregationParams.beta']").type( + "0.8", + ); + + cy.get("select[name='trainingInformation.aggregationStrategy']").select( + "mean", + ); + cy.get( + "input[name='trainingInformation.aggregationParams.clippingRadius']", + ).should("not.exist"); + + fillRemainingTabularFieldsAndSubmit(); + + cy.wait("@posted") + .its("request.body.task.trainingInformation") + .should("not.have.property", "aggregationParams"); + + cy.get("@posted") + .its("request.body.task") + .then(deserializeTaskFromJSON) + .should("deep.equal", { + id: "aggregation-reset-task", + dataType: "tabular", + displayInformation: { + title: "aggregation reset title", + summary: { + preview: "preview", + overview: "overview", + }, + dataExample: [{ name: "name", data: "data" }], + }, + trainingInformation: { + scheme: "federated", + aggregationStrategy: "mean", + epochs: 10, + batchSize: 5, + roundDuration: 2, + validationSplit: 0, + minNbOfParticipants: 2, + inputColumns: ["input"], + categoricalColumns: {}, + outputColumn: "output", + tensorBackend: "tfjs", + }, + } satisfies Task<"tabular", "federated">); +}); + +for (const aggregation of [ + { + scheme: "federated", + aggregationStrategy: "byzantine", + aggregationParams: { clippingRadius: 1.0, maxIterations: 1, beta: 0.9 }, + }, + { + scheme: "decentralized", + aggregationStrategy: "secure", + aggregationParams: { maxShareValue: 100 }, + maxConnectionRetry: 3, + maxPeerConnectionTime: 60_000, + maxModelSyncTime: 30_000, + }, +] as const) { + it(`falls back to default aggregation parameters (${aggregation.aggregationStrategy})`, () => { + visitAndFillTabularTaskBasics( + "aggregation-default-task", + "aggregation default title", + ); + + cy.get("select[name='trainingInformation.scheme']").select( + aggregation.scheme, + ); + cy.get("select[name='trainingInformation.aggregationStrategy']").select( + aggregation.aggregationStrategy, + ); + for (const key of Object.keys(aggregation.aggregationParams)) { + cy.get( + `input[name='trainingInformation.aggregationParams.${key}']`, + ).should("have.value", ""); + } + + fillRemainingTabularFieldsAndSubmit(); + + cy.wait("@posted") + .its("request.body.task.trainingInformation.aggregationParams") + .should("deep.equal", aggregation.aggregationParams); + + cy.get("@posted") + .its("request.body.task") + .then(deserializeTaskFromJSON) + .should("deep.equal", { + id: "aggregation-default-task", + dataType: "tabular", + displayInformation: { + title: "aggregation default title", + summary: { + preview: "preview", + overview: "overview", + }, + dataExample: [{ name: "name", data: "data" }], + }, + trainingInformation: { + ...aggregation, + epochs: 10, + batchSize: 5, + roundDuration: 2, + validationSplit: 0, + minNbOfParticipants: 2, + inputColumns: ["input"], + categoricalColumns: {}, + outputColumn: "output", + tensorBackend: "tfjs", + }, + }); + }); +} + +function visitAndFillTabularTaskBasics(id: string, title: string): void { + cy.intercept( + { hostname: "server", pathname: "tasks", method: "POST" }, + { statusCode: 200 }, + ).as("posted"); + + cy.visit("/create"); + + cy.get("form").should("be.visible"); // Wait for the form to be fully loaded + + cy.get("input[name='id']").type(id); + cy.get("select[name='dataType']").select("tabular"); + + cy.get("input[name='displayInformation.title']").type(title); + cy.get("input[name='displayInformation.summary.preview']").type("preview"); + cy.get("textarea[name='displayInformation.summary.overview']").type( + "overview", + ); + cy.contains("Example tabular data").within(() => { + cy.contains("add example").click(); + cy.get("input[name='displayInformation.dataExample[0].name']").type("name"); + cy.get("input[name='displayInformation.dataExample[0].data']").type("data"); + }); +} + +function fillRemainingTabularFieldsAndSubmit(): void { + cy.get("input[name='trainingInformation.epochs']").type("10"); + cy.get("input[name='trainingInformation.batchSize']").type("5"); + cy.get("input[name='trainingInformation.roundDuration']").type("2"); + cy.get("input[name='trainingInformation.validationSplit']").type("0"); + cy.get("input[name='trainingInformation.minNbOfParticipants']").type("2"); + cy.contains("Input columns names").within(() => { + cy.get("input[name='trainingInformation.inputColumns[0]']").type("input"); + }); + cy.get("input[name='trainingInformation.outputColumn']").type("output"); + + const model = tf.sequential({ + layers: [ + tf.layers.conv2d({ + inputShape: [32, 32, 3], + kernelSize: 3, + filters: 16, + activation: "relu", + }), + ], + }); + model.compile({ loss: "hinge", optimizer: "sgd" }); + cy.wrap(getArtifacts(model)) + .then((artifacts) => JSON.stringify(artifacts)) + .then((json) => new TextEncoder().encode(json)) + .then((raw) => + cy.get("input[type='file']").selectFile(new Uint8Array(raw), { + force: true, // input is hidden + }), + ); + cy.get("select[name='model.loss']").select("hinge"); + cy.get("select[name='model.optimizer.name']").select("sgd"); + cy.get("input[name='model.optimizer.learningRate']").type("0.01"); + + cy.get("button[type='submit']").click(); +} + async function getArtifacts( model: tf.LayersModel, ): Promise { diff --git a/webapp/src/components/task_creation_form/TaskCreationForm.vue b/webapp/src/components/task_creation_form/TaskCreationForm.vue index a8344560b..bda2235e5 100644 --- a/webapp/src/components/task_creation_form/TaskCreationForm.vue +++ b/webapp/src/components/task_creation_form/TaskCreationForm.vue @@ -445,6 +445,7 @@ placeholder="1.0" as="input" type="number" + min="0" step="any" /> @@ -797,7 +798,12 @@ watch([scheme, form], ([scheme, form]) => { if (scheme === "local") { form.setFieldValue("trainingInformation.aggregationStrategy", "mean"); - } else if (scheme === "federated" && aggregationStrategy.value === "secure") { + } else if ( + scheme === "federated" && + !( + FEDERATED_AGGREGATION_STRATEGIES as readonly AggregationStrategy[] + ).includes(aggregationStrategy.value) + ) { form.setFieldValue("trainingInformation.aggregationStrategy", "mean"); } });