The following repo aims at extending dEngine with model architectures from timm (PyTorch Image Models).
Disclaimer: This project is an independent extension for dEngine. It is not associated with, endorsed by, or affiliated with timm, its maintainers, or Hugging Face in any way. timm is used here as a third-party dependency, like any other.
It plugs into dEngine's usual config system (BUILTINS, load_experiment_from_yamls, load_engine, etc.) and adds:
- a thin
create_modelwrapper around timm's model factory, so any timm architecture can be dropped in as a dEngineclient.local_model - ready-to-use experiment scripts showing centralized and decentralized (federated) training with a timm model on CIFAR-10
pip install https://github.com/DecentralizedLearning/dengine-timm
This will also pull in timm as a dependency.
A fully working example is provided in main.py. The important steps:
-
Import
create_modelfrom the plugin alongside dEngine's usual imports:from dengine_timm import create_model
-
Instantiate any timm model just like you would with timm directly — every architecture name and argument supported by
timm.create_modelworks here too:MNASNET = create_model('mnasnet_050', pretrained=False)
-
Compose your config file list by mixing dEngine core configs (scenario, graph, partitioning, dataset) as usual:
FEDERATED_CONFIGS = [ BUILTINS.CORE.SCENARIOS.DECENTRALIZED_HOMOGENOUS, BUILTINS.CORE.GRAPH.STAR_51, BUILTINS.CORE.PARTITIONING.NONIID, BUILTINS.CORE.DATASETS.MNIST, ]
-
Load and run as usual with
load_experiment_from_yamls/load_engine, overridingclient.local_modelwith your timm model wherever you'd normally define one:experiment = load_experiment_from_yamls( files=FEDERATED_CONFIGS, overrides=convert_to_nested_dict({ "name": "cifar10,FedAvg", "client.target": DecAvgClient.__name__, **MNASNET, # any other client/training_engine/etc. overrides }), experiments_directory_root=str(simulation_args.output_directory.absolute()), seed=simulation_args.seed, )
Because model construction happens in plain Python via create_model(...), you can swap architectures by changing a single string (e.g. 'mnasnet_050' → 'resnet18', 'efficientnet_b0', etc.) — no extra config files needed.
main.py shows both a centralized baseline and several decentralized topologies (BA graph, ER graph, star/FedAvg) trained on CIFAR-10 with the same timm-backed model, run either sequentially or in parallel across processes:
python main.py --concurrent-runs 4Useful flags:
--concurrent-runs N— run up toNconfigurations in parallel viamultiprocessing.Pool--experiment_name_filter REGEX— only run experiments whose name matches the given regex (can be passed multiple times)--debug— skip actual training/testing, useful for quickly checking that all configs load and wire together correctly
The plot above was produced with:
$ PYTHON_GIL=0 python main.py --seed 123 --concurrent_runs 5 --num_parallel_clients 50
