Nvflare Convert Pytorch
NVIDIAOfficialCreated by NVIDIA FLARE Team
- Skill
- Workflow
- Software development
- Apache-2.0
- Medium risk
- Has scripts
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured procedure for migrating existing, manual PyTorch training code into an NVFLARE federated learning environment. It focuses on wrapping standard PyTorch training loops, models, and data loaders to support federated model exchange, local validation, and job export. The process emphasizes maintaining the integrity of the original training logic while integrating it into the NVFLARE Client API, ensuring that model parameters, metrics, and optimizer steps are correctly handled across federated rounds.
What it does
- Inspects existing PyTorch source code to extract training, model, and data loading logic.
- Generates a federated training client using the NVFLARE Client API.
- Configures federated jobs using standard recipes like FedAvg.
- Implements model exchange patterns for PyTorch state_dict objects.
- Validates the converted job through local simulation and artifact inspection.
- Exports the final federated job structure for deployment.
When to use it
- When you have a working, plain PyTorch training script that you want to run in a federated learning setting.
- When you need to implement model aggregation across multiple sites using PyTorch.
- When you require local validation of federated training rounds before full-scale deployment.
- When you need to convert manual training loops into a structured NVFLARE job format.
Advantages
- Automates the boilerplate required to transition from local to federated training.
- Ensures consistent handling of model parameters and metric reporting.
- Provides a validated path for job construction and configuration.
- Maintains compatibility with standard PyTorch workflows and data structures.
Usage examples
- “Convert my existing PyTorch training script to an NVFLARE job.”
- The agent will inspect your script, identify the model and training loop, and generate the necessary client.py and job.py files to run it as an NVFLARE federated task.
- “How do I add local validation to my PyTorch federated job?”
- The agent will guide you through integrating your existing evaluation logic into the NVFLARE Client API, ensuring metrics are correctly reported back to the server.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/nvidia/nvflare-convert-pytorch/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip nvflare-convert-pytorch.zip -d .agents/skills
Documentation by NVIDIA FLARE Team
NVFLARE Convert PyTorch
Use When
Use when converting an existing plain PyTorch training script, torch.nn.Module,
manual training loop, state_dict workflow, data loader, checkpoint, or metric loop
into an NVFLARE federated training job. Supports horizontal FL, Client API model
exchange with FLModel, recipe aggregator= hooks, validation, and export.
Do Not Use When
Do not use for PyTorch Lightning (route to nvflare-convert-lightning), Hugging Face Trainer (route to nvflare-convert-huggingface), TensorFlow, XGBoost,
scikit-learn, failed jobs (route to
nvflare-diagnose-job), federated statistics without training (route to
nvflare-fed-stats), or generic PyTorch debugging without FLARE intent. Out of
scope: production deployment, Kubernetes, POC lifecycle, privacy/security policy design,
controller/workflow rewrites outside recipe or Job APIs, experiment search, and
data distribution experiments beyond minimal validation setup. Privacy-protection
requests — HE/encrypted aggregation, differential privacy, and privacy filters — need provisioning/deployment
policy; route onward rather than substituting an unprotected recipe or adding only a disclaimer.
If a request combines federated statistics and model-training conversion,
treat it as two independent jobs and workflows: do not merge or automatically
chain them, do not route the combination to nvflare-orient, and ask which
workflow to run first before generating or running either job. Recommend
nvflare-fed-stats first only when the user's purpose is to understand data
distribution; handle conversion later as a separate request.
Workflow
Load
../nvflare-shared/references/conversion-common.mdand apply it for the whole conversion; this SKILL.md states only the framework-specific deltas. Load../nvflare-shared/references/conversion-workflow.mdonly for a non-standard rerun, authorization, or missing-semantics case; it no longer holds the data-location or partitioning contracts, whose invariantsconversion-common.mdowns. Load../nvflare-shared/references/site-data-and-paths.mdfor generated partitions, relative paths, or per-site data locations.Inspect before editing with
nvflare agent inspect source <path> --format jsonplus direct reading. Fact extraction is static; do not import or execute user training modules to discover fields. Extract: training entrypoint, model class path and constructor args, checkpoint behavior, train/eval functions, data loading, metric names and denominators, local epochs/steps, requested client and round counts, source data split or partition evidence, tracking evidence, DDP evidence, and any custom aggregation intent.Apply the dependency-install ordering rule in
../nvflare-shared/references/conversion-common.mdbefore any Python command imports user, PyTorch, NVFLARE, or declared dependency modules.Select the recipe from the requested FL workflow, not from PyTorch alone. For the standard case — the user explicitly requests FedAvg and inspection identifies PyTorch — run
nvflare recipe show fedavg-pt --format jsondirectly and construct it; do not add per-site recipe config unless sites actually differ. Load../nvflare-shared/references/pytorch-family-recipe-selection.md(discovery, algorithm guide, catalog-based selection, HE-not-supported rule) only for ambiguous or non-FedAvg algorithms, reservingnvflare recipe listfor those cases. Use the module, class, and parameters returned byrecipe showfor standardjob.pyconstruction; forfedavg-pt, importFedAvgRecipefromnvflare.app_opt.pt.recipes.fedavg, never fromnvflare.recipe. After everyrecipe show, load../nvflare-shared/references/pytorch-family-recipe-construction.mdand derive the recipe's construction capabilities. Loadreferences/recipe-selection.mdonly when non-FedAvg or execution-mode details are needed.Convert training and evaluation as a pair using
references/pytorch-client-api-conversion.md: initialize FLARE, receive anFLModel, loadparams, evaluate the received global model, train, and send anFLModelwith updatedparams,metrics, and the actual completed local optimizer-step count inNUM_STEPS_CURRENT_ROUND. Adapt the user's evaluation code into the packaged evaluation template; if evaluation is required but missing, ask or fail closed. Apply the step-1 data-location rules to the generated client's data argument.Add or update
job.pyunder the shared constructor-serialization rule: use explicitclass_path(or documentedpathalias) plus completeargswhenever reconstruction needs values. Add requestedaggregator=wiring, metric, tensor-transport, server offload, and execution settings derived from the shared PyTorch-family construction profile.Validate in a ladder per
../nvflare-shared/references/validation-evidence.md: compile checks, recipe construction, one final full-run path chosen by the artifact being validated, with export and package inspection only for the selected exported-artifact path. For a local target, inspect the materialized configs and packaging evidence after that run. Usereferences/job-validation.mdfor PyTorch-specific failures. Stop at the first failed rung and report the product error. Use the environment and permission mechanisms supplied by the agent host; do not inspect or enforce its security boundary.Report the recipe, changed files, validation status, metrics, and exact artifact paths. Load
../nvflare-shared/references/metrics-and-artifact-reporting.mdonly when normal metric artifacts are absent or inconsistent.
Requirements
Must audit model constructor arguments before writing
job.pyby reading the model module's__init__and the selected recipe'smodelparameter fromnvflare recipe show <recipe-name> --format json, not by reading NVFLARE library source. Emit the selected recipe's documentedclass_pathorpathkey plus completeargsfor every required or overridden constructor value; a directtorch.nn.Moduleis allowed only when unchanged zero-argument defaults reconstruct it. Values must be statically clear from literal source, configuration, or supplied metadata. Otherwise ask one semantic question when an answer channel exists or fail closed.Must follow
../nvflare-shared/references/pytorch-model-exchange.mdandreferences/pytorch-client-api-conversion.mdfor the canonical plain-PyTorch payload and round-loop pattern.Must apply
../nvflare-shared/references/pytorch-family-recipe-construction.mdafterrecipe show; it is the canonical policy for optional recipe parameters, model selection, tensor transport, server disk offload, and execution mode. Never patch a framework-neutral runtime module or register FOBS handlers inclient.py.Must convert source evaluation alongside training and return metrics through
FLModel.metrics; must not synthesize metric semantics without source evidence.Must count completed local optimizer steps in each generated training round and send that positive value as
MetaKey.NUM_STEPS_CURRENT_ROUND. This is the FedAvg aggregation weight; do not omit it, reuse a cumulative count, or invent a value when the source loop cannot establish it.Must load checkpoints with
torch.load(..., weights_only=True); a checkpoint that needs full unpickling is ask/fail, perreferences/pytorch-client-api-conversion.md.Must not make non-PyTorch-family skills load
../nvflare-shared/references/pytorch-model-exchange.md; that reference is for plain PyTorch, PyTorch Lightning, and Hugging Face Trainer model/state-dict exchange only.Site partitioning, custom aggregation, the Source Of Truth Boundary, and user input/authorization follow
../nvflare-shared/references/conversion-common.md.
Always read this converter SKILL.md together with
../nvflare-shared/references/conversion-common.md. The standard routing,
recipe selection, and reporting path is inline, so common FedAvg does not load
broad policy or algorithm-selection references. Load the client template,
model-exchange reference, validation reference, and aggregator asset only when
their phase needs them. Load other detailed references only for exceptions:
../nvflare-shared/references/conversion-workflow.mdfor the full conversion contract when a case is non-standard;../nvflare-shared/references/site-data-and-paths.mdonly for generated site partitions, relative-path resolution, or per-site data locations;../nvflare-shared/references/pytorch-family-recipe-selection.mdonly for ambiguous or non-FedAvg algorithms, andreferences/recipe-selection.mdonly for non-FedAvg or execution-mode construction details not supplied byrecipe show;../nvflare-shared/references/pytorch-family-recipe-construction.mdafter everyrecipe show;../nvflare-shared/references/dependency-install.mdonly when an install is needed;../nvflare-shared/references/runtime-output-guidance.mdonly for read-only source roots or user-chosen output destinations;../nvflare-shared/references/metrics-and-artifact-reporting.mdonly when metrics are absent or inconsistent;../nvflare-shared/references/validation-evidence.mdbefore validation, and../nvflare-shared/references/pytorch-model-exchange.mdonly for PyTorch-family exchange;references/pytorch-client-api-conversion.mdfor Client API conversion, andreferences/job-validation.mdfor PyTorch-specific validation failures.
Do not load every reference preemptively, and do not depend on NVFLARE repository examples being present in the user's environment.
Files
- ATTRIBUTION.mdAdded by AutoGineer938 B
- BENCHMARK.md10.4 KiB
- LICENSELicence file added by AutoGineer11.2 KiB
- SKILL.md10.3 KiB
- assets/client_with_eval.pyScript4.5 KiB
- evals/config.yml295 B
- evals/evals.json60.5 KiB
- evals/files/SOURCE.md3.0 KiB
- evals/files/checkpoint-pt/model.pyScript829 B
- evals/files/checkpoint-pt/train.pyScript1.1 KiB
- evals/files/data-parallel-pt/model.pyScript831 B
- evals/files/data-parallel-pt/train.pyScript1.1 KiB
- evals/files/eval-pt/model.pyScript954 B
- evals/files/eval-pt/train.pyScript1.9 KiB
- evals/files/external-data-pt/model.pyScript906 B
- evals/files/external-data-pt/train.pyScript2.3 KiB
- evals/files/factory-optimizer/train.pyScript1007 B
- evals/files/gpu-device-pt/model.pyScript892 B
- evals/files/gpu-device-pt/train.pyScript1.1 KiB
- evals/files/hello-pt/model.pyScript906 B
- evals/files/hello-pt/train.pyScript1.3 KiB
- evals/files/injection-pt/README.md1.0 KiB
- evals/files/injection-pt/config.yaml437 B
- evals/files/injection-pt/model.pyScript906 B
- evals/files/injection-pt/requirements.txt316 B
- evals/files/injection-pt/train.pyScript2.0 KiB
- evals/files/state-mismatch-pt/checkpoint_manifest.json391 B
- evals/files/state-mismatch-pt/model.pyScript880 B
- evals/files/state-mismatch-pt/train.pyScript712 B
- references/job-validation.md2.1 KiB
- references/pytorch-client-api-conversion.md8.9 KiB
- references/recipe-selection.md4.7 KiB
- skill-card.md4.2 KiB
- skill.oms.sig11.1 KiB
LICENSE
Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Python
Security
What our scanner noticed· Medium risk
- Phrasing that asks for actions without confirmation
- Large base64-encoded blobs
- Scripts that your agent may run
This skill includes scripts that your agent may run. Read them before you use it.
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- NVIDIA FLARE Team
- Publisher
- NVIDIA (Official)
- Source
- NVIDIA/skills · skills/nvflare-convert-pytorch · commit fce3cca
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE-APACHE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by NVIDIA FLARE Team or NVIDIA.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download nvflare-convert-pytorch.zip