• bitcoinBitcoin(BTC)$79,196.00-1.17%
  • ethereumEthereum(ETH)$2,490.30-0.97%
  • tetherTether(USDT)$1.00-0.01%
  • binancecoinBNB(BNB)$740.42-1.61%
  • rippleXRP(XRP)$1.40-1.59%
  • usd-coinUSDC(USDC)$1.000.00%
  • solanaSolana(SOL)$103.83-2.10%
  • tronTRON(TRX)$0.334239-0.29%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.060.00%
  • zcashZcash(ZEC)$1,136.15-5.39%
  • HyperliquidHyperliquid(HYPE)$84.93-3.26%
  • dogecoinDogecoin(DOGE)$0.0913340.37%
  • RainRain(RAIN)$0.016292-2.64%
  • USDSUSDS(USDS)$1.000.01%
  • moneroMonero(XMR)$517.83-4.04%
  • chainlinkChainlink(LINK)$12.77-3.74%
  • whitebitWhiteBIT Coin(WBT)$76.623.73%
  • leo-tokenLEO Token(LEO)$9.20-2.14%
  • cardanoCardano(ADA)$0.221448-1.84%
  • stellarStellar(XLM)$0.1934302.03%
  • bitcoin-cashBitcoin Cash(BCH)$260.13-0.30%
  • daiDai(DAI)$1.00-0.01%
  • Ethena USDeEthena USDe(USDE)$1.00-0.01%
  • litecoinLitecoin(LTC)$55.53-0.92%
  • uniswapUniswap(UNI)$6.85-4.98%
  • USD1USD1(USD1)$1.000.00%
  • CantonCanton(CC)$0.105505-5.02%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.39-3.18%
  • hedera-hashgraphHedera(HBAR)$0.0822660.05%
  • avalanche-2Avalanche(AVAX)$8.082.00%
  • suiSui(SUI)$0.831.19%
  • Global DollarGlobal Dollar(USDG)$1.000.00%
  • shiba-inuShiba Inu(SHIB)$0.000005-1.39%
  • nearNEAR Protocol(NEAR)$2.33-3.60%
  • paypal-usdPayPal USD(PYUSD)$1.000.00%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • crypto-com-chainCronos(CRO)$0.057204-1.04%
  • tether-goldTether Gold(XAUT)$4,417.25-0.04%
  • MemeCoreMemeCore(M)$1.163.54%
  • Circle USYCCircle USYC(USYC)$1.140.00%
  • BittensorBittensor(TAO)$259.84-2.32%
  • okbOKB(OKB)$117.132.64%
  • Ripple USDRipple USD(RLUSD)$1.000.01%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.150.03%
  • AsterAster(ASTER)$0.77-1.75%
  • mantleMantle(MNT)$0.632.89%
  • aaveAave(AAVE)$132.32-2.58%
  • pax-goldPAX Gold(PAXG)$4,421.020.01%
  • OndoOndo(ONDO)$0.384409-1.84%
  • polkadotPolkadot(DOT)$1.074.67%
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

Anthropic’s $15 Billion Credit Line Sets Stage for IPO

How To Reset The Camera Settings On Your iPhone

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

Anthropic’s  Billion Credit Line Sets Stage for IPO
AI & Technology

Anthropic’s $15 Billion Credit Line Sets Stage for IPO

September 8, 2026
How To Reset The Camera Settings On Your iPhone
AI & Technology

How To Reset The Camera Settings On Your iPhone

September 8, 2026
How AI Is Eroding the First Rung of the Tech Job Ladder
AI & Technology

How AI Is Eroding the First Rung of the Tech Job Ladder

September 8, 2026
OpenAI Rolls Out Its Most Advanced Model Yet
AI & Technology

OpenAI Rolls Out Its Most Advanced Model Yet

September 7, 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
Grupo Financiero Inbursa Adopts Harvey Across Its Legal Organization – Unite.AI

Grupo Financiero Inbursa Adopts Harvey Across Its Legal Organization – Unite.AI

September 7, 2026
Hochul says AI companies are ‘flooding the zone’ with data centers

Hochul says AI companies are ‘flooding the zone’ with data centers

September 5, 2026
Oil prices hit six-week high amid US-Iran conflict — but drivers could soon get relief at the pump

Oil prices hit six-week high amid US-Iran conflict — but drivers could soon get relief at the pump

September 7, 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!