• bitcoinBitcoin(BTC)$60,392.000.22%
  • ethereumEthereum(ETH)$1,683.84-0.35%
  • tetherTether(USDT)$1.000.00%
  • binancecoinBNB(BNB)$552.510.06%
  • usd-coinUSDC(USDC)$1.000.01%
  • rippleXRP(XRP)$0.940.74%
  • solanaSolana(SOL)$70.920.84%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.061.72%
  • tronTRON(TRX)$0.3038530.15%
  • HyperliquidHyperliquid(HYPE)$62.101.26%
  • zcashZcash(ZEC)$682.10-10.41%
  • dogecoinDogecoin(DOGE)$0.0563390.97%
  • moneroMonero(XMR)$458.44-11.82%
  • leo-tokenLEO Token(LEO)$9.090.82%
  • whitebitWhiteBIT Coin(WBT)$60.954.23%
  • chainlinkChainlink(LINK)$9.252.51%
  • USDSUSDS(USDS)$1.000.02%
  • cardanoCardano(ADA)$0.1482632.03%
  • Ethena USDeEthena USDe(USDE)$1.00-0.04%
  • stellarStellar(XLM)$0.126647-0.76%
  • daiDai(DAI)$1.000.03%
  • bitcoin-cashBitcoin Cash(BCH)$209.262.13%
  • nearNEAR Protocol(NEAR)$3.040.78%
  • litecoinLitecoin(LTC)$43.793.02%
  • CantonCanton(CC)$0.075310-2.66%
  • avalanche-2Avalanche(AVAX)$6.58-0.55%
  • tether-goldTether Gold(XAUT)$3,561.14-0.28%
  • USD1USD1(USD1)$1.00-0.03%
  • uniswapUniswap(UNI)$4.64-1.45%
  • Ripple USDRipple USD(RLUSD)$1.000.01%
  • the-open-networkGram (prev. Toncoin)(GRAM)$0.96-0.34%
  • suiSui(SUI)$0.670.33%
  • Global DollarGlobal Dollar(USDG)$1.000.00%
  • hedera-hashgraphHedera(HBAR)$0.0538483.70%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.150.02%
  • paypal-usdPayPal USD(PYUSD)$1.000.02%
  • BittensorBittensor(TAO)$183.401.24%
  • quant-networkQuant(QNT)$147.391.16%
  • shiba-inuShiba Inu(SHIB)$0.0000040.99%
  • Spiko Amundi Overnight Swap Fund (EUR)Spiko Amundi Overnight Swap Fund (EUR)(EURSAFO)$1.120.00%
  • Circle USYCCircle USYC(USYC)$1.150.00%
  • crypto-com-chainCronos(CRO)$0.039898-0.71%
  • MemeCoreMemeCore(M)$0.82-0.18%
  • RainRain(RAIN)$0.002484-9.32%
  • okbOKB(OKB)$82.190.56%
  • Falcon USDFalcon USD(USDF)$1.000.04%
  • United StablesUnited Stables(U)$1.000.02%
  • pax-goldPAX Gold(PAXG)$3,558.19-0.34%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • BitwayBitway(BTW)$0.9910.20%
TradePoint.io
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop
No Result
View All Result
TradePoint.io
No Result
View All Result

Step by Step Guide to Build and Compare FedAvg and FedProx Federated Learning on Non-IID CIFAR-10 with NVIDIA FLARE

May 25, 2026
in AI & Technology
Reading Time: 2 mins read
A A
Step by Step Guide to Build and Compare FedAvg and FedProx Federated Learning on Non-IID CIFAR-10 with NVIDIA FLARE
ShareShareShareShareShare
CLIENT_SCRIPT += r'''
def main():
   p = argparse.ArgumentParser()
   p.add_argument("--num_sites", type=int, default=3)
   p.add_argument("--alpha", type=float, default=0.3)
   p.add_argument("--local_epochs", type=int, default=1)
   p.add_argument("--mu", type=float, default=0.0)
   p.add_argument("--max_samples", type=int, default=4000)
   p.add_argument("--batch_size", type=int, default=64)
   p.add_argument("--lr", type=float, default=0.01)
   p.add_argument("--data_root", type=str, default="/tmp/nvflare/data")
   p.add_argument("--results_dir", type=str, default="/tmp/nvflare/results")
   p.add_argument("--tag", type=str, default="fedavg")
   args = p.parse_args()
   device = "cuda" if torch.cuda.is_available() else "cpu"
   tf = T.Compose([T.ToTensor(),
                   T.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
   train_set = torchvision.datasets.CIFAR10(args.data_root, train=True,  download=False, transform=tf)
   test_set  = torchvision.datasets.CIFAR10(args.data_root, train=False, download=False, transform=tf)
   flare.init()
   site_name = flare.get_site_name()
   site_id   = int(site_name.split("-")[-1]) - 1
   labels   = np.array(train_set.targets)
   my_idx   = dirichlet_partition(labels, args.num_sites, args.alpha)[site_id]
   if len(my_idx) > args.max_samples:
       my_idx = my_idx[:args.max_samples]
   train_loader = DataLoader(Subset(train_set, my_idx), batch_size=args.batch_size, shuffle=True)
   test_loader  = DataLoader(test_set, batch_size=512, shuffle=False)
   print(f"[{site_name}] mu={args.mu}  local samples={len(my_idx)}", flush=True)
   model     = Net().to(device)
   optimizer = torch.optim.SGD(model.parameters(), lr=args.lr, momentum=0.9)
   criterion = nn.CrossEntropyLoss()
   while flare.is_running():
       input_model = flare.receive()
       rnd = input_model.current_round
       global_state = {k: torch.as_tensor(v) for k, v in input_model.params.items()}
       model.load_state_dict(global_state)
       acc = evaluate(model, test_loader, device)
       if site_id == 0:
           with open(os.path.join(args.results_dir, args.tag + ".csv"), "a", newline="") as f:
               csv.writer(f).writerow([rnd, acc])
       print(f"[{site_name}] round {rnd}: global test acc = {acc:.4f}", flush=True)
       global_w = [w.detach().clone() for w in model.parameters()]
       model.train()
       steps = 0
       for _ in range(args.local_epochs):
           for x, y in train_loader:
               x, y = x.to(device), y.to(device)
               optimizer.zero_grad()
               loss = criterion(model(x), y)
               if args.mu > 0:
                   prox = sum(((w - g) ** 2).sum() for w, g in zip(model.parameters(), global_w))
                   loss = loss + (args.mu / 2.0) * prox
               loss.backward()
               optimizer.step()
               steps += 1
       out = flare.FLModel(
           params={k: v.cpu().numpy() for k, v in model.state_dict().items()},
           metrics={"test_accuracy": acc},
           meta={"NUM_STEPS_CURRENT_ROUND": steps},
       )
       flare.send(out)
if __name__ == "__main__":
   main()
'''
with open("client_train.py", "w") as f:
   f.write(CLIENT_SCRIPT)
sys.path.insert(0, os.getcwd())
from client_train import Net

Credit: Source link

YOU MAY ALSO LIKE

Backloggd Urges Users To Change Their Passwords After A Breach

1Password Says It Was Hacked But Users’ Vaults Are Safe

ShareTweetSendSharePin

Related Posts

Backloggd Urges Users To Change Their Passwords After A Breach
AI & Technology

Backloggd Urges Users To Change Their Passwords After A Breach

November 26, 2026
1Password Says It Was Hacked But Users’ Vaults Are Safe
AI & Technology

1Password Says It Was Hacked But Users’ Vaults Are Safe

November 26, 2026
Canada Invests 0 Million More to Expand AI Compute Access Fund – Unite.AI
AI & Technology

Canada Invests $700 Million More to Expand AI Compute Access Fund – Unite.AI

November 26, 2026
Workers At GTA 6 Studio Rockstar Games Vote Overwhelmingly Against Union Recognition
AI & Technology

Workers At GTA 6 Studio Rockstar Games Vote Overwhelmingly Against Union Recognition

November 26, 2026
Next Post
Avacta Group Plc (AVCTF) Q4 2025 Earnings Call Transcript

Avacta Group Plc (AVCTF) Q4 2025 Earnings Call Transcript

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

No Result
View All Result
Amazon delivery drone crashes into home’s garage

Amazon delivery drone crashes into home’s garage

November 24, 2026
Asian Stocks Set to Fall as AI Enthusiasm Fades: Markets Wrap – Bloomberg.com

Asian Stocks Set to Fall as AI Enthusiasm Fades: Markets Wrap – Bloomberg.com

November 20, 2026
Above The Noise: 10 Things Investors Can Be Thankful For

Above The Noise: 10 Things Investors Can Be Thankful For

November 20, 2026

About

Learn more

Our Services

Legal

Privacy Policy

Terms of Use

Bloggers

Learn more

Article Links

Contact

Advertise

Ask us anything

©2020- TradePoint.io - All rights reserved!

Tradepoint.io, being just a publishing and technology platform, is not a registered broker-dealer or investment adviser. So we do not provide investment advice. Rather, brokerage services are provided to clients of Tradepoint.io by independent SEC-registered broker-dealers and members of FINRA/SIPC. Every form of investing carries some risk and past performance is not a guarantee of future results. “Tradepoint.io“, “Instant Investing” and “My Trading Tools” are registered trademarks of Apperbuild, LLC.

This website is operated by Apperbuild, LLC. We have no link to any brokerage firm and we do not provide investment advice. Every information and resource we provide is solely for the education of our readers. © 2020 Apperbuild, LLC. All rights reserved.

No Result
View All Result
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop

© 2023 - TradePoint.io - All Rights Reserved!