• bitcoinBitcoin(BTC)$65,816.00-0.29%
  • ethereumEthereum(ETH)$1,793.021.34%
  • tetherTether(USDT)$1.00-0.04%
  • binancecoinBNB(BNB)$605.83-1.12%
  • rippleXRP(XRP)$1.22-0.69%
  • usd-coinUSDC(USDC)$1.000.00%
  • solanaSolana(SOL)$73.670.23%
  • tronTRON(TRX)$0.317199-0.07%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.040.76%
  • HyperliquidHyperliquid(HYPE)$74.757.88%
  • dogecoinDogecoin(DOGE)$0.0874800.43%
  • USDSUSDS(USDS)$1.00-0.01%
  • leo-tokenLEO Token(LEO)$9.68-0.69%
  • RainRain(RAIN)$0.0141373.16%
  • zcashZcash(ZEC)$511.41-2.26%
  • stellarStellar(XLM)$0.2246745.89%
  • moneroMonero(XMR)$348.25-1.16%
  • cardanoCardano(ADA)$0.172867-2.18%
  • whitebitWhiteBIT Coin(WBT)$54.00-0.04%
  • CantonCanton(CC)$0.160907-2.58%
  • chainlinkChainlink(LINK)$8.351.48%
  • USD1USD1(USD1)$1.00-0.04%
  • Ethena USDeEthena USDe(USDE)$1.00-0.01%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.65-2.36%
  • LABLAB(LAB)$13.6637.83%
  • bitcoin-cashBitcoin Cash(BCH)$214.44-3.06%
  • daiDai(DAI)$1.00-0.03%
  • MemeCoreMemeCore(M)$3.178.71%
  • hedera-hashgraphHedera(HBAR)$0.081310-1.10%
  • litecoinLitecoin(LTC)$45.640.14%
  • suiSui(SUI)$0.813.24%
  • Circle USYCCircle USYC(USYC)$1.130.00%
  • nearNEAR Protocol(NEAR)$2.33-2.82%
  • avalanche-2Avalanche(AVAX)$6.952.16%
  • shiba-inuShiba Inu(SHIB)$0.000005-0.24%
  • paypal-usdPayPal USD(PYUSD)$1.00-0.03%
  • Global DollarGlobal Dollar(USDG)$1.000.00%
  • crypto-com-chainCronos(CRO)$0.059951-3.85%
  • tether-goldTether Gold(XAUT)$4,306.730.06%
  • BittensorBittensor(TAO)$258.44-0.91%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • worldcoin-wldWorldcoin(WLD)$0.6915.18%
  • uniswapUniswap(UNI)$3.5322.61%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.130.00%
  • pax-goldPAX Gold(PAXG)$4,316.180.05%
  • World Liberty FinancialWorld Liberty Financial(WLFI)$0.0602770.86%
  • mantleMantle(MNT)$0.57-0.99%
  • OndoOndo(ONDO)$0.3776772.27%
  • AsterAster(ASTER)$0.672.83%
  • polkadotPolkadot(DOT)$1.032.23%
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

How to Build Memory-Efficient Transformers with xFormers Using Packed Sequences, GQA, ALiBi, SwiGLU, and Causal Attention

June 17, 2026
in AI & Technology
Reading Time: 2 mins read
A A
How to Build Memory-Efficient Transformers with xFormers Using Packed Sequences, GQA, ALiBi, SwiGLU, and Causal Attention
ShareShareShareShareShare

YOU MAY ALSO LIKE

The Dell XPS 13 Laptop Is Available Starting Today

The Webb Telescope Has Captured Its First ‘Bulge Fossil Fragment’

print("\n" + "="*70 + "\n4. Variable-length packed batch — no padding waste\n" + "="*70)
seqlens = [37, 120, 8, 200]
total = sum(seqlens)
H, K = 8, 64
q = torch.randn(1, total, H, K, device=device, dtype=torch.float16)
k = torch.randn(1, total, H, K, device=device, dtype=torch.float16)
v = torch.randn(1, total, H, K, device=device, dtype=torch.float16)
try:
   bias = ab.BlockDiagonalMask.from_seqlens(seqlens)
   out_packed = xops.memory_efficient_attention(q, k, v, attn_bias=bias)
   s0 = seqlens[0]
   ref0 = vanilla_attention(q[:, :s0], k[:, :s0], v[:, :s0]).half()
   print("packed shape         :", tuple(out_packed.shape), "(all", total, "tokens, no pad)")
   print("segment-0 max diff   : {:.2e}".format((out_packed[:, :s0] - ref0).abs().max().item()))
   cbias = ab.BlockDiagonalCausalMask.from_seqlens(seqlens)
   _ = xops.memory_efficient_attention(q, k, v, attn_bias=cbias)
   print("-> also did a packed CAUSAL pass. This is how vLLM-style engines")
   print("   batch requests of different lengths with zero padding overhead.")
   splits = bias.split(out_packed)
   print("recovered segments   :", [tuple(t.shape) for t in splits])
except Exception as e:
   print("BlockDiagonalMask path skipped on this version/backend:", repr(e))
print("\n" + "="*70 + "\n5. Grouped-query attention (5-D BMGHK layout)\n" + "="*70)
B, M, K = 2, 256, 64
n_q_heads, n_kv_heads = 8, 2
G, Hq = n_kv_heads, n_q_heads // n_kv_heads
try:
   qg = torch.randn(B, M, G, Hq, K, device=device, dtype=torch.float16)
   kg = torch.randn(B, M, G, 1,  K, device=device, dtype=torch.float16)
   vg = torch.randn(B, M, G, 1,  K, device=device, dtype=torch.float16)
   out_gqa = xops.memory_efficient_attention(qg, kg, vg)
   print("GQA output shape     :", tuple(out_gqa.shape), "= [B, M, G, Hq, K]")
   print(f"-> {n_q_heads} query heads, only {n_kv_heads} KV heads: smaller KV-cache,")
   print("   which is exactly what Llama-/Mistral-class models use at inference.")
except Exception as e:
   print("GQA 5-D path skipped on this version/backend:", repr(e))

Credit: Source link

ShareTweetSendSharePin

Related Posts

The Dell XPS 13 Laptop Is Available Starting Today
AI & Technology

The Dell XPS 13 Laptop Is Available Starting Today

June 16, 2026
The Webb Telescope Has Captured Its First ‘Bulge Fossil Fragment’
AI & Technology

The Webb Telescope Has Captured Its First ‘Bulge Fossil Fragment’

June 16, 2026
Z.ai’s open-weights GLM-5.2 beats GPT-5.5 on multiple long-horizon coding benchmarks for 1/6th the cost
AI & Technology

Z.ai’s open-weights GLM-5.2 beats GPT-5.5 on multiple long-horizon coding benchmarks for 1/6th the cost

June 16, 2026
Xfinity Introduces Same-Day Wi-Fi For New Customers.
AI & Technology

Xfinity Introduces Same-Day Wi-Fi For New Customers.

June 16, 2026
Next Post
Invesco Short Duration High Yield Municipal Fund Q1 2026 Commentary (Mutual Fund:ISHAX)

Invesco Short Duration High Yield Municipal Fund Q1 2026 Commentary (Mutual Fund:ISHAX)

Leave a Reply Cancel reply

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

Search

No Result
View All Result
French President Macron scolds audience at youth event for making too much noise

French President Macron scolds audience at youth event for making too much noise

June 10, 2026
Controversy surrounding data center approval connected to Shark Tank’s Kevin O’Leary

Controversy surrounding data center approval connected to Shark Tank’s Kevin O’Leary

June 12, 2026
Apple Watch Alternatives That Will Last For 7 Days On A Charge

Apple Watch Alternatives That Will Last For 7 Days On A Charge

June 13, 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!