• bitcoinBitcoin(BTC)$80,341.004.49%
  • ethereumEthereum(ETH)$2,412.466.63%
  • tetherTether(USDT)$1.000.05%
  • binancecoinBNB(BNB)$715.683.33%
  • rippleXRP(XRP)$1.303.66%
  • usd-coinUSDC(USDC)$1.000.02%
  • solanaSolana(SOL)$95.313.89%
  • tronTRON(TRX)$0.319424-0.90%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.051.53%
  • zcashZcash(ZEC)$1,284.727.07%
  • HyperliquidHyperliquid(HYPE)$83.810.83%
  • dogecoinDogecoin(DOGE)$0.0766813.58%
  • moneroMonero(XMR)$634.091.43%
  • USDSUSDS(USDS)$1.000.04%
  • whitebitWhiteBIT Coin(WBT)$77.705.14%
  • chainlinkChainlink(LINK)$11.364.96%
  • leo-tokenLEO Token(LEO)$9.340.39%
  • cardanoCardano(ADA)$0.1959074.95%
  • stellarStellar(XLM)$0.1666694.22%
  • bitcoin-cashBitcoin Cash(BCH)$279.833.26%
  • nearNEAR Protocol(NEAR)$3.995.88%
  • uniswapUniswap(UNI)$7.637.45%
  • daiDai(DAI)$1.000.00%
  • Ethena USDeEthena USDe(USDE)$1.000.07%
  • litecoinLitecoin(LTC)$56.004.93%
  • RainRain(RAIN)$0.005957-8.35%
  • CantonCanton(CC)$0.0990633.25%
  • avalanche-2Avalanche(AVAX)$8.673.81%
  • suiSui(SUI)$0.925.27%
  • USD1USD1(USD1)$1.000.05%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.170.52%
  • tether-goldTether Gold(XAUT)$4,089.323.59%
  • hedera-hashgraphHedera(HBAR)$0.0721875.23%
  • quant-networkQuant(QNT)$201.106.11%
  • Global DollarGlobal Dollar(USDG)$1.000.02%
  • shiba-inuShiba Inu(SHIB)$0.0000053.51%
  • BittensorBittensor(TAO)$234.515.60%
  • paypal-usdPayPal USD(PYUSD)$1.000.04%
  • crypto-com-chainCronos(CRO)$0.0519764.62%
  • Ripple USDRipple USD(RLUSD)$1.000.03%
  • EthenaEthena(ENA)$0.1802606.05%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.150.07%
  • okbOKB(OKB)$110.483.39%
  • Circle USYCCircle USYC(USYC)$1.140.01%
  • pepePepe(PEPE)$0.0000053.54%
  • aaveAave(AAVE)$130.924.68%
  • OndoOndo(ONDO)$0.4061066.34%
  • Pump.funPump.fun(PUMP)$0.0042490.42%
  • MemeCoreMemeCore(M)$0.84-2.21%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
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
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

YOU MAY ALSO LIKE

Snap Has More Than 30 Million Paid Subscribers Across Snapchat+ And Other Plans

Atmospheric AI Secures $10M Seed for Procurement Modeling Push – Unite.AI

ShareTweetSendSharePin

Related Posts

Snap Has More Than 30 Million Paid Subscribers Across Snapchat+ And Other Plans
AI & Technology

Snap Has More Than 30 Million Paid Subscribers Across Snapchat+ And Other Plans

November 4, 2026
Atmospheric AI Secures M Seed for Procurement Modeling Push – Unite.AI
AI & Technology

Atmospheric AI Secures $10M Seed for Procurement Modeling Push – Unite.AI

November 4, 2026
Perplexity Adds Live Web Grounding to Its Decisions API – Unite.AI
AI & Technology

Perplexity Adds Live Web Grounding to Its Decisions API – Unite.AI

November 4, 2026
Pangram Expands Its AI Detection Tools To Video And Images
AI & Technology

Pangram Expands Its AI Detection Tools To Video And Images

November 4, 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

Raffensperger says he hasn’t spoken to Trump since 2021 call asking him to ‘find’ votes

October 29, 2026
Chilean police conduct rescues after severe flooding

Chilean police conduct rescues after severe flooding

October 29, 2026
Harley-Davidson’s Electric Motorbike Brand Has ‘Substantial Doubt’ About Its Future

Harley-Davidson’s Electric Motorbike Brand Has ‘Substantial Doubt’ About Its Future

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