• bitcoinBitcoin(BTC)$80,104.00-1.63%
  • ethereumEthereum(ETH)$2,317.98-2.16%
  • tetherTether(USDT)$1.000.01%
  • binancecoinBNB(BNB)$747.92-0.65%
  • rippleXRP(XRP)$1.29-3.07%
  • usd-coinUSDC(USDC)$1.000.01%
  • solanaSolana(SOL)$100.06-2.63%
  • tronTRON(TRX)$0.331188-0.10%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.030.09%
  • zcashZcash(ZEC)$1,247.08-5.39%
  • HyperliquidHyperliquid(HYPE)$79.15-3.61%
  • dogecoinDogecoin(DOGE)$0.078070-2.99%
  • moneroMonero(XMR)$595.70-1.83%
  • USDSUSDS(USDS)$1.000.00%
  • whitebitWhiteBIT Coin(WBT)$76.89-1.67%
  • chainlinkChainlink(LINK)$11.47-3.20%
  • leo-tokenLEO Token(LEO)$9.450.04%
  • cardanoCardano(ADA)$0.199379-3.87%
  • stellarStellar(XLM)$0.168583-1.98%
  • nearNEAR Protocol(NEAR)$4.36-7.88%
  • bitcoin-cashBitcoin Cash(BCH)$279.10-7.87%
  • RainRain(RAIN)$0.006914-1.79%
  • daiDai(DAI)$1.000.02%
  • Ethena USDeEthena USDe(USDE)$1.000.00%
  • litecoinLitecoin(LTC)$57.28-1.01%
  • uniswapUniswap(UNI)$7.02-2.29%
  • USD1USD1(USD1)$1.000.00%
  • avalanche-2Avalanche(AVAX)$8.72-3.48%
  • CantonCanton(CC)$0.096636-6.74%
  • suiSui(SUI)$0.91-3.26%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.21-2.67%
  • hedera-hashgraphHedera(HBAR)$0.073726-3.60%
  • tether-goldTether Gold(XAUT)$4,020.55-0.62%
  • Global DollarGlobal Dollar(USDG)$1.000.00%
  • paypal-usdPayPal USD(PYUSD)$1.00-0.01%
  • BittensorBittensor(TAO)$248.84-3.27%
  • shiba-inuShiba Inu(SHIB)$0.000005-2.63%
  • BitwayBitway(BTW)$1.877.65%
  • quant-networkQuant(QNT)$191.75-5.10%
  • crypto-com-chainCronos(CRO)$0.053123-1.83%
  • EthenaEthena(ENA)$0.196568-5.27%
  • Ripple USDRipple USD(RLUSD)$1.000.02%
  • MemeCoreMemeCore(M)$1.06-5.12%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.15-0.10%
  • Circle USYCCircle USYC(USYC)$1.140.01%
  • okbOKB(OKB)$110.830.23%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • pepePepe(PEPE)$0.000005-0.83%
  • aaveAave(AAVE)$130.69-3.60%
  • OndoOndo(ONDO)$0.408442-2.93%
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

A Coding Implementation to Compress and Benchmark Instruction-Tuned LLMs with FP8, GPTQ, and SmoothQuant Quantization using llmcompressor

May 17, 2026
in AI & Technology
Reading Time: 2 mins read
A A
A Coding Implementation to Compress and Benchmark Instruction-Tuned LLMs with FP8, GPTQ, and SmoothQuant Quantization using llmcompressor
ShareShareShareShareShare
import subprocess, sys
def pip(*pkgs):
   subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", *pkgs])
pip("llmcompressor", "compressed-tensors",
   "transformers>=4.45", "accelerate", "datasets")
import os, gc, time, json, math
from pathlib import Path
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from datasets import load_dataset
assert torch.cuda.is_available(), \
   "Enable a GPU: Runtime > Change runtime type > T4 GPU"
print("GPU:", torch.cuda.get_device_name(0),
     "| CUDA:", torch.version.cuda,
     "| torch:", torch.__version__)
MODEL_ID = "Qwen/Qwen2.5-0.5B-Instruct"
WORKDIR = Path("/content/quant_lab"); WORKDIR.mkdir(exist_ok=True)
os.chdir(WORKDIR)
def free_mem():
   gc.collect(); torch.cuda.empty_cache()
def dir_size_gb(path):
   total = 0
   for root, _, files in os.walk(path):
       for f in files:
           total += os.path.getsize(os.path.join(root, f))
   return total / 1e9
def time_generation(model, tok, prompt, max_new_tokens=64):
   """Greedy decode; reports latency & tokens/sec after a brief warmup."""
   inputs = tok(prompt, return_tensors="pt").to(model.device)
   _ = model.generate(**inputs, max_new_tokens=4, do_sample=False)
   torch.cuda.synchronize()
   t0 = time.time()
   out = model.generate(**inputs, max_new_tokens=max_new_tokens,
                        do_sample=False, pad_token_id=tok.eos_token_id)
   torch.cuda.synchronize()
   dt = time.time() - t0
   new_ids = out[0][inputs["input_ids"].shape[1]:]
   return tok.decode(new_ids, skip_special_tokens=True), dt, max_new_tokens/dt
@torch.no_grad()
def wikitext_ppl(model, tok, seq_len=512, max_chunks=20, stride=512):
   """Light WikiText-2 perplexity probe (fast, indicative)."""
   ds = load_dataset("wikitext", "wikitext-2-raw-v1", split="test")
   text = "\n\n".join(t for t in ds["text"][:400] if t.strip())
   enc = tok(text, return_tensors="pt").input_ids.to(model.device)
   nll_sum, tok_count = 0.0, 0
   for begin in range(0, enc.size(1) - seq_len, stride):
       chunk = enc[:, begin:begin+seq_len]
       out = model(chunk, labels=chunk)
       nll_sum += out.loss.float().item() * seq_len
       tok_count += seq_len
       if tok_count // seq_len >= max_chunks: break
   return math.exp(nll_sum / tok_count)
results = {}
PROMPT = ("<|im_start|>user\nIn two sentences, explain why post-training "
         "quantization works for large language models.<|im_end|>\n"
         "<|im_start|>assistant\n")
def benchmark(label, model_path_or_id):
   free_mem()
   print(f"\n──── benchmarking: {label} ────")
   tok = AutoTokenizer.from_pretrained(model_path_or_id)
   m = AutoModelForCausalLM.from_pretrained(
           model_path_or_id, torch_dtype="auto", device_map="cuda").eval()
   sample, dt, tps = time_generation(m, tok, PROMPT)
   ppl = wikitext_ppl(m, tok)
   size = dir_size_gb(model_path_or_id) if os.path.isdir(str(model_path_or_id)) else None
   results[label] = {"size_gb": size, "ppl": round(ppl, 3),
                     "latency_s": round(dt, 3), "tok_per_s": round(tps, 1),
                     "sample": sample.strip().replace("\n", " ")[:180]}
   print(json.dumps(results[label], indent=2))
   del m; free_mem()

Credit: Source link

YOU MAY ALSO LIKE

Hackers Leaked Details Of More Than 41,000 Homeland Security Personnel

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

ShareTweetSendSharePin

Related Posts

Hackers Leaked Details Of More Than 41,000 Homeland Security Personnel
AI & Technology

Hackers Leaked Details Of More Than 41,000 Homeland Security Personnel

October 29, 2026
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
Next Post
Meta to lay off 10% of company as Microsoft offers buyouts

Meta to lay off 10% of company as Microsoft offers buyouts

Leave a Reply Cancel reply

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

Search

No Result
View All Result
Warnock says Democrats are ‘missing a real opportunity’ to win in the South: Full interview

Warnock says Democrats are ‘missing a real opportunity’ to win in the South: Full interview

October 23, 2026
Doctor says Pope Leo has ‘one of the more treatable’ cancers

Doctor says Pope Leo has ‘one of the more treatable’ cancers

October 26, 2026
Bend superintendent speaks after elementary school shooting

Bend superintendent speaks after elementary school shooting

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