• bitcoinBitcoin(BTC)$79,962.00-1.06%
  • Midas Fasanara Global EuroMidas Fasanara Global Euro(MGLOEURO)$111,813.00-0.36%
  • ethereumEthereum(ETH)$2,311.94-1.67%
  • tetherTether(USDT)$1.000.02%
  • binancecoinBNB(BNB)$753.251.23%
  • rippleXRP(XRP)$1.30-2.32%
  • usd-coinUSDC(USDC)$1.000.01%
  • solanaSolana(SOL)$100.00-1.92%
  • tronTRON(TRX)$0.330759-0.09%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.030.08%
  • zcashZcash(ZEC)$1,242.82-4.93%
  • HyperliquidHyperliquid(HYPE)$78.97-2.94%
  • dogecoinDogecoin(DOGE)$0.078233-1.87%
  • moneroMonero(XMR)$589.48-4.23%
  • USDSUSDS(USDS)$1.000.00%
  • whitebitWhiteBIT Coin(WBT)$76.70-1.26%
  • chainlinkChainlink(LINK)$11.46-2.39%
  • leo-tokenLEO Token(LEO)$9.462.32%
  • cardanoCardano(ADA)$0.198413-3.86%
  • stellarStellar(XLM)$0.168130-1.86%
  • nearNEAR Protocol(NEAR)$4.45-5.35%
  • bitcoin-cashBitcoin Cash(BCH)$279.91-5.92%
  • RainRain(RAIN)$0.006420-9.07%
  • daiDai(DAI)$1.000.00%
  • Ethena USDeEthena USDe(USDE)$1.000.01%
  • litecoinLitecoin(LTC)$57.30-0.35%
  • uniswapUniswap(UNI)$7.04-1.87%
  • USD1USD1(USD1)$1.00-0.01%
  • avalanche-2Avalanche(AVAX)$8.73-2.90%
  • CantonCanton(CC)$0.096031-2.72%
  • suiSui(SUI)$0.91-2.62%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.22-1.64%
  • hedera-hashgraphHedera(HBAR)$0.073821-3.01%
  • tether-goldTether Gold(XAUT)$4,020.13-0.03%
  • Global DollarGlobal Dollar(USDG)$1.000.00%
  • paypal-usdPayPal USD(PYUSD)$1.000.00%
  • BittensorBittensor(TAO)$247.93-3.47%
  • shiba-inuShiba Inu(SHIB)$0.000005-1.76%
  • quant-networkQuant(QNT)$193.19-4.16%
  • BitwayBitway(BTW)$1.79-0.20%
  • crypto-com-chainCronos(CRO)$0.052688-1.74%
  • EthenaEthena(ENA)$0.196797-4.68%
  • Ripple USDRipple USD(RLUSD)$1.000.01%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.15-0.08%
  • Circle USYCCircle USYC(USYC)$1.140.01%
  • MemeCoreMemeCore(M)$1.04-7.76%
  • okbOKB(OKB)$111.441.29%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • pepePepe(PEPE)$0.0000056.82%
  • aaveAave(AAVE)$130.99-2.92%
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

NVIDIA Releases Nemotron 3.5 Transcribe: An Open 30B MoE Model for 40-Language Transcription with ~4B Active Parameters

FCC Chair Wants To Let Prisons Jam Illegal Cellphones

ShareTweetSendSharePin

Related Posts

NVIDIA Releases Nemotron 3.5 Transcribe: An Open 30B MoE Model for 40-Language Transcription with ~4B Active Parameters
AI & Technology

NVIDIA Releases Nemotron 3.5 Transcribe: An Open 30B MoE Model for 40-Language Transcription with ~4B Active Parameters

October 29, 2026
FCC Chair Wants To Let Prisons Jam Illegal Cellphones
AI & Technology

FCC Chair Wants To Let Prisons Jam Illegal Cellphones

October 28, 2026
Microsoft Posts 19% Revenue Growth as Azure Revenue Jumps 48% – Unite.AI
AI & Technology

Microsoft Posts 19% Revenue Growth as Azure Revenue Jumps 48% – Unite.AI

October 28, 2026
Google Rolls Out AI Mode Ads in 10 Countries, Multiturn Ads in U.S. – Unite.AI
AI & Technology

Google Rolls Out AI Mode Ads in 10 Countries, Multiturn Ads in U.S. – Unite.AI

October 28, 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
Latina scientist works to save endangered manatees in Florida

Latina scientist works to save endangered manatees in Florida

October 27, 2026
Ukraine resumes strikes on Russia’s oil refineries

Ukraine resumes strikes on Russia’s oil refineries

October 25, 2026
Hurricane Isaias pounding Gulf Coast

Hurricane Isaias pounding Gulf Coast

October 28, 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!