• bitcoinBitcoin(BTC)$78,046.00-1.54%
  • ethereumEthereum(ETH)$2,468.02-1.83%
  • tetherTether(USDT)$1.000.00%
  • binancecoinBNB(BNB)$717.20-4.90%
  • rippleXRP(XRP)$1.38-4.06%
  • usd-coinUSDC(USDC)$1.00-0.01%
  • solanaSolana(SOL)$101.14-3.45%
  • tronTRON(TRX)$0.3394450.29%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.03-0.84%
  • zcashZcash(ZEC)$1,214.86-1.55%
  • HyperliquidHyperliquid(HYPE)$83.08-4.22%
  • dogecoinDogecoin(DOGE)$0.085263-5.99%
  • RainRain(RAIN)$0.0163031.06%
  • USDSUSDS(USDS)$1.000.01%
  • moneroMonero(XMR)$511.801.92%
  • whitebitWhiteBIT Coin(WBT)$80.59-1.86%
  • chainlinkChainlink(LINK)$11.79-6.24%
  • leo-tokenLEO Token(LEO)$9.190.08%
  • cardanoCardano(ADA)$0.213240-3.51%
  • stellarStellar(XLM)$0.179764-5.60%
  • bitcoin-cashBitcoin Cash(BCH)$248.06-4.22%
  • daiDai(DAI)$1.000.02%
  • Ethena USDeEthena USDe(USDE)$1.00-0.02%
  • USD1USD1(USD1)$1.00-0.01%
  • CantonCanton(CC)$0.104758-3.11%
  • litecoinLitecoin(LTC)$52.42-3.81%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.37-2.30%
  • uniswapUniswap(UNI)$5.98-12.09%
  • avalanche-2Avalanche(AVAX)$7.77-3.22%
  • hedera-hashgraphHedera(HBAR)$0.076381-4.05%
  • Global DollarGlobal Dollar(USDG)$1.000.00%
  • nearNEAR Protocol(NEAR)$2.440.71%
  • suiSui(SUI)$0.76-7.14%
  • shiba-inuShiba Inu(SHIB)$0.000005-5.14%
  • paypal-usdPayPal USD(PYUSD)$1.000.00%
  • crypto-com-chainCronos(CRO)$0.057699-3.88%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • MemeCoreMemeCore(M)$1.211.26%
  • tether-goldTether Gold(XAUT)$4,404.40-0.02%
  • Circle USYCCircle USYC(USYC)$1.140.01%
  • Ripple USDRipple USD(RLUSD)$1.000.00%
  • BittensorBittensor(TAO)$252.28-3.39%
  • okbOKB(OKB)$112.62-1.87%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.150.20%
  • mantleMantle(MNT)$0.59-6.49%
  • AsterAster(ASTER)$0.72-6.01%
  • aaveAave(AAVE)$124.00-4.66%
  • pax-goldPAX Gold(PAXG)$4,408.93-0.01%
  • polkadotPolkadot(DOT)$1.10-6.24%
  • World Liberty FinancialWorld Liberty Financial(WLFI)$0.0563090.92%
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

YOU MAY ALSO LIKE

Anthropic Discloses Fourth Cyber Incident in Alignment Assessment – Unite.AI

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

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

ShareTweetSendSharePin

Related Posts

Anthropic Discloses Fourth Cyber Incident in Alignment Assessment – Unite.AI
AI & Technology

Anthropic Discloses Fourth Cyber Incident in Alignment Assessment – Unite.AI

September 10, 2026
LandingAI Releases Agentic Document Extraction Gen2 with DPT-3 Pro and DPT-3 Verity
AI & Technology

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

September 10, 2026
Apple Wallet Is Not The Same As Apple Pay: Here’s How They Differ
AI & Technology

Apple Wallet Is Not The Same As Apple Pay: Here’s How They Differ

September 9, 2026
Google Open-Sources Mantis: A Modular Skills Toolkit That Lets Coding Agents Find, Reproduce and Patch Vulnerabilities
AI & Technology

Google Open-Sources Mantis: A Modular Skills Toolkit That Lets Coding Agents Find, Reproduce and Patch Vulnerabilities

September 9, 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
German chancellor vows to stay in office despite AfD triumph in state election – The Guardian

German chancellor vows to stay in office despite AfD triumph in state election – The Guardian

September 8, 2026
An HSA Is the Only Triple-Tax-Advantaged Account Available

An HSA Is the Only Triple-Tax-Advantaged Account Available

September 7, 2026
Warsh’s Hawkish Turn: What It May Mean for Investors

Warsh’s Hawkish Turn: What It May Mean for Investors

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