• bitcoinBitcoin(BTC)$77,249.001.45%
  • ethereumEthereum(ETH)$2,108.681.84%
  • tetherTether(USDT)$1.000.03%
  • binancecoinBNB(BNB)$661.041.68%
  • rippleXRP(XRP)$1.351.40%
  • usd-coinUSDC(USDC)$1.000.00%
  • solanaSolana(SOL)$85.291.62%
  • tronTRON(TRX)$0.3715322.00%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.030.00%
  • dogecoinDogecoin(DOGE)$0.1022151.54%
  • HyperliquidHyperliquid(HYPE)$61.31-0.77%
  • USDSUSDS(USDS)$1.000.00%
  • zcashZcash(ZEC)$651.49-0.61%
  • leo-tokenLEO Token(LEO)$9.98-0.64%
  • cardanoCardano(ADA)$0.2444082.31%
  • moneroMonero(XMR)$386.630.51%
  • bitcoin-cashBitcoin Cash(BCH)$350.902.87%
  • chainlinkChainlink(LINK)$9.502.49%
  • whitebitWhiteBIT Coin(WBT)$56.831.48%
  • CantonCanton(CC)$0.1669671.31%
  • the-open-networkToncoin(TON)$1.9814.01%
  • stellarStellar(XLM)$0.1495923.19%
  • USD1USD1(USD1)$1.00-0.03%
  • Ethena USDeEthena USDe(USDE)$1.000.05%
  • daiDai(DAI)$1.00-0.01%
  • suiSui(SUI)$1.053.50%
  • litecoinLitecoin(LTC)$52.831.46%
  • avalanche-2Avalanche(AVAX)$9.332.80%
  • RainRain(RAIN)$0.0080317.25%
  • MemeCoreMemeCore(M)$2.942.77%
  • hedera-hashgraphHedera(HBAR)$0.0883241.09%
  • paypal-usdPayPal USD(PYUSD)$1.000.00%
  • nearNEAR Protocol(NEAR)$2.7615.19%
  • shiba-inuShiba Inu(SHIB)$0.0000061.16%
  • crypto-com-chainCronos(CRO)$0.0689931.15%
  • Circle USYCCircle USYC(USYC)$1.130.00%
  • Global DollarGlobal Dollar(USDG)$1.000.00%
  • BittensorBittensor(TAO)$281.814.59%
  • tether-goldTether Gold(XAUT)$4,548.170.99%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • mantleMantle(MNT)$0.650.84%
  • polkadotPolkadot(DOT)$1.273.27%
  • pax-goldPAX Gold(PAXG)$4,557.170.96%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.13-0.54%
  • OndoOndo(ONDO)$0.4388193.05%
  • uniswapUniswap(UNI)$3.33-0.01%
  • World Liberty FinancialWorld Liberty Financial(WLFI)$0.0614792.06%
  • HTX DAOHTX DAO(HTX)$0.0000021.35%
  • AsterAster(ASTER)$0.69-1.08%
  • okbOKB(OKB)$83.231.42%
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

YOU MAY ALSO LIKE

Here’s The First Car From Jony Ive’s Design House

Epic Games Reveals A First Look At Unreal Engine 6 With A Rocket League Makeover

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

ShareTweetSendSharePin

Related Posts

Here’s The First Car From Jony Ive’s Design House
AI & Technology

Here’s The First Car From Jony Ive’s Design House

May 25, 2026
Epic Games Reveals A First Look At Unreal Engine 6 With A Rocket League Makeover
AI & Technology

Epic Games Reveals A First Look At Unreal Engine 6 With A Rocket League Makeover

May 25, 2026
Star Citizen Has Raised  Billion, Remains In Early Access After Nine Years
AI & Technology

Star Citizen Has Raised $1 Billion, Remains In Early Access After Nine Years

May 25, 2026
Pope Leo Calls For AI To Serve Humanity And Not Concentrate Power
AI & Technology

Pope Leo Calls For AI To Serve Humanity And Not Concentrate Power

May 25, 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
Matthew Tuttle on NVDA Earnings and Where the Real AI Upside Is

Matthew Tuttle on NVDA Earnings and Where the Real AI Upside Is

May 20, 2026
Iguana? On A Pizza?? What’s Going On?!?

Iguana? On A Pizza?? What’s Going On?!?

May 20, 2026
The Apple Sports App Expands To 90 New Markets Ahead Of The World Cup

The Apple Sports App Expands To 90 New Markets Ahead Of The World Cup

May 19, 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!