Close Menu
    Facebook X (Twitter) Instagram
    • Privacy Policy
    • Terms Of Service
    • Social Media Disclaimer
    • DMCA Compliance
    • Anti-Spam Policy
    Facebook X (Twitter) Instagram
    Fintech Fetch
    • Home
    • Crypto News
      • Bitcoin
      • Ethereum
      • Altcoins
      • Blockchain
      • DeFi
    • AI News
    • Stock News
    • Learn
      • AI for Beginners
      • AI Tips
      • Make Money with AI
    • Reviews
    • Tools
      • Best AI Tools
      • Crypto Market Cap List
      • Stock Market Overview
      • Market Heatmap
    • Contact
    Fintech Fetch
    Home»AI News»How to Speed Up Transformer Training Using NVIDIA Apex (FusedAdam, FusedLayerNorm) and Native torch.amp
    How to Speed Up Transformer Training Using NVIDIA Apex (FusedAdam, FusedLayerNorm) and Native torch.amp
    AI News

    How to Speed Up Transformer Training Using NVIDIA Apex (FusedAdam, FusedLayerNorm) and Native torch.amp

    June 2, 20263 Mins Read
    Share
    Facebook Twitter LinkedIn Pinterest Email
    ledger

    rewrite this content and keep HTML tags as is. This is content from rss feed and I don’t need their *Daily Debrief Newsletter*, their tags from bottom like this *Share this articleCategoriesTags*, Editorial Process section, phrases like *Featured image from Peakpx, chart from Tradingview.com*, SPECIAL OFFERS and similar sections – just remove such sections and save only article itself:

    print(“\n### SECTION D: end-to-end Transformer (vanilla fp32 vs Apex fused + AMP) ###”)
    VOCAB, D, NHEAD, LAYERS, SEQ, BATCH, STEPS = 2000, 256, 4, 4, 128, 32, 60
    class Block(torch.nn.Module):
    def __init__(self, d, nhead, norm_cls):
    super().__init__()
    self.attn = torch.nn.MultiheadAttention(d, nhead, batch_first=True)
    self.ff = torch.nn.Sequential(torch.nn.Linear(d, 4 * d), torch.nn.GELU(),
    torch.nn.Linear(4 * d, d))
    self.n1, self.n2 = norm_cls(d), norm_cls(d)
    def forward(self, x):
    h = self.n1(x); x = x + self.attn(h, h, h, need_weights=False)[0]
    return x + self.ff(self.n2(x))
    class TinyTransformer(torch.nn.Module):
    def __init__(self, norm_cls):
    super().__init__()
    self.emb = torch.nn.Embedding(VOCAB, D)
    self.blocks = torch.nn.ModuleList([Block(D, NHEAD, norm_cls) for _ in range(LAYERS)])
    self.norm = norm_cls(D)
    self.head = torch.nn.Linear(D, VOCAB)
    def forward(self, idx):
    x = self.emb(idx)
    for b in self.blocks:
    x = b(x)
    return self.head(self.norm(x))
    g = torch.Generator(device=”cpu”).manual_seed(0)
    data = torch.randint(0, VOCAB, (BATCH, SEQ + 1), generator=g).to(DEV)
    inp, tgt = data[:, :-1], data[:, 1:]
    lossfn = torch.nn.CrossEntropyLoss()
    def run_training(use_apex):
    torch.manual_seed(0)
    norm_cls = (FusedLayerNorm if (use_apex and HAS_FLN and APEX_OK) else torch.nn.LayerNorm)
    model = TinyTransformer(norm_cls).to(DEV)
    if use_apex and HAS_AMP_C and APEX_OK:
    optimizer = FusedAdam(model.parameters(), lr=3e-4)
    else:
    optimizer = torch.optim.AdamW(model.parameters(), lr=3e-4)
    scaler = torch.amp.GradScaler(“cuda”, enabled=use_apex)
    def one_step():
    optimizer.zero_grad(set_to_none=True)
    with torch.amp.autocast(“cuda”, dtype=torch.float16, enabled=use_apex):
    logits = model(inp)
    loss = lossfn(logits.reshape(-1, VOCAB), tgt.reshape(-1))
    scaler.scale(loss).backward()
    scaler.step(optimizer)
    scaler.update()
    return loss
    for _ in range(5):
    one_step()
    torch.cuda.synchronize()
    t0 = time.perf_counter()
    for _ in range(STEPS):
    loss = one_step()
    torch.cuda.synchronize()
    dt = time.perf_counter() – t0
    return loss.item(), (STEPS * BATCH * SEQ) / dt, dt
    loss_v, tps_v, dt_v = run_training(use_apex=False)
    print(f” vanilla (fp32, nn.LayerNorm, AdamW) : ”
    f”{dt_v:5.2f}s | {tps_v:9.0f} tok/s | final loss {loss_v:.3f}”)
    if APEX_OK and (HAS_AMP_C or HAS_FLN):
    loss_a, tps_a, dt_a = run_training(use_apex=True)
    print(f” apex (fp16, FusedLayerNorm, FusedAdam) : ”
    f”{dt_a:5.2f}s | {tps_a:9.0f} tok/s | final loss {loss_a:.3f}”)
    print(f” —-> speedup: {tps_a / tps_v:0.2f}x throughput”)
    else:
    print(” apex path SKIPPED (no fused kernels built)”)
    print(“\n” + “=” * 78)
    print(“DONE. Key takeaways:”)
    print(” – FusedAdam/FusedLayerNorm/FusedRMSNorm are the still-relevant Apex pieces;”)
    print(” speedups grow with model size & parameter count (tiny demo understates it).”)
    print(” – apex.amp is deprecated -> prefer torch.amp.autocast + torch.amp.GradScaler.”)
    print(” – FusedAdam composes cleanly with native torch.amp (Section D).”)
    print(” – On real workloads, also try a larger model and bf16 autocast (no scaler needed).”)
    print(“=” * 78)
    frase
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Fintech Fetch Editorial Team
    • Website

    Related Posts

    Supply chains detect fast, act slow: How AI agents fix it

    Supply chains detect fast, act slow: How AI agents fix it

    September 11, 2026
    LandingAI Releases Agentic Document Extraction Gen2 with DPT-3 Pro and DPT-3 Verity

    LandingAI Releases Agentic Document Extraction Gen2 with DPT-3 Pro and DPT-3 Verity

    September 10, 2026
    Walter Torous named executive director of MIT Center for Real Estate | MIT News

    Walter Torous named executive director of MIT Center for Real Estate | MIT News

    September 9, 2026
    MG Ship adds AI route optimisation as logistics returns accelerate

    MG Ship adds AI route optimisation as logistics returns accelerate

    September 8, 2026
    Add A Comment

    Comments are closed.

    Join our email newsletter and get news & updates into your inbox for free.


    Privacy Policy

    Thanks! We sent confirmation message to your inbox.

    synthesia
    Latest Posts
    Supply chains detect fast, act slow: How AI agents fix it

    Supply chains detect fast, act slow: How AI agents fix it

    September 11, 2026
    The SIMPLEST Way To Make Money Online With Claude AI In 2026

    The SIMPLEST Way To Make Money Online With Claude AI In 2026

    September 11, 2026
    Liquid Hackers Call Blockstream 'Delusional, Greedy, and Arrogant,' Demand 10% Bounty

    Liquid Hackers Accuse Blockstream of Being ‘Delusional, Greedy, and Arrogant,’ Seek 10% Reward

    September 11, 2026
    Cointelegraph

    Bitcoin ETF Withdrawals Hit $167 Million as Ether and Solana ETFs Experience Recovery

    September 10, 2026
    Toncoin

    Ton Mini Apps Surpass 100 Million Monthly Active Users on Telegram

    September 10, 2026
    frase
    LEGAL INFORMATION
    • Privacy Policy
    • Terms Of Service
    • Social Media Disclaimer
    • DMCA Compliance
    • Anti-Spam Policy
    Top Insights
    Bitcoin.com News

    ZEC Falls Below $1,100 Amid Market Selloff Causing Altcoin Decline

    September 11, 2026
    Bitcoin.com News

    Bitmine Acquires 28,086 ETH as Ethereum Reserves Reach $14.8 Billion

    September 11, 2026
    kraken
    Facebook X (Twitter) Instagram Pinterest
    © 2026 FintechFetch.com - All rights reserved.

    Type above and press Enter to search. Press Esc to cancel.