Instructions to use Meanblock/JEV-CPU with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Meanblock/JEV-CPU with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-classification", model="Meanblock/JEV-CPU")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Meanblock/JEV-CPU", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 4,739 Bytes
7845694 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | #!/usr/bin/env python3
"""
SemIf ๋ฅผ ์ด Linux CPU PC์์ ๋ก์ปฌ ์คํํ๊ธฐ ์ํ ์์ shim.
SemIf( github.com/TheoLeeCJ/SemIf )์ ์ ์ผํ GPU ๊ฐ์ ์ง์ ์
core.load_causal_model() ๋ฟ์ด๋ค. ์ค์ฝ์ด๋ง ๋ก์ง(direct.score / shared.score_shared)์
device = next(model.parameters()).device ๋ฅผ ๋ฐ๋ผ๊ฐ๋ฏ๋ก CPU์์ ๊ทธ๋๋ก ๋์ํ๋ค.
์ฌ๊ธฐ์๋ CUDA ๋ก๋ ๋์ CPU(float32) ๋ก๋๋ฅผ ์จ์ ๋ชจ๋ธ์ ์ฌ๋ฆฌ๊ณ ,
SemIf ์ ์ค์ direct.score() ๋ฅผ ํธ์ถํด '์ต์
ํ๋ฅ (semantic if)'์ ์ฝ๋๋ค.
์ ์ :
- SemIf ์ ์ฅ์๊ฐ /tmp/SemIf ์ clone ๋์ด ์์ (SEMIF_DIR ๋ก ๋ณ๊ฒฝ ๊ฐ๋ฅ)
- pip install torch transformers accelerate (CPU)
์ฌ์ฉ:
python semif_cpu.py
"""
import os
import sys
import time
# SemIf ์์ค ์์น ํ์ง: 1) SEMIF_DIR ํ๊ฒฝ๋ณ์, 2) ์ด ํ์ผ๊ณผ ๊ฐ์ ๋ ํฌ์ ./src,
# 3) /tmp/SemIf (๊ฐ๋ฐ์ฉ clone). ์ฒ์ ๋ฐ๊ฒฌ๋๋ ๊ณณ์ ์ฌ์ฉํ๋ค.
_HERE = os.path.dirname(os.path.abspath(__file__))
_CANDIDATES = [
os.environ.get("SEMIF_DIR"),
_HERE, # ๋ ํฌ ๋ฃจํธ์ src/semif_phase1 ์ด ์๋ ๊ฒฝ์ฐ (JEV-CPU)
"/tmp/SemIf", # ๊ฐ๋ฐ์ฉ clone
]
for _base in _CANDIDATES:
if _base and os.path.isdir(os.path.join(_base, "src", "semif_phase1")):
SEMIF_DIR = _base
break
else:
raise RuntimeError(
"SemIf ์์ค๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค. SEMIF_DIR ํ๊ฒฝ๋ณ์๋ก ๊ฒฝ๋ก๋ฅผ ์ง์ ํ์ธ์ "
"(src/semif_phase1 ๋ฅผ ํฌํจํด์ผ ํจ)."
)
sys.path.insert(0, os.path.join(SEMIF_DIR, "src"))
import torch
import transformers
from semif_phase1.direct import score as direct_score
# openjev.com/SemIf ๊ฐ ์ฐ๋ ๊ฐ์ฅ ์์ ๋ชจ๋ธ. ์๊ฒฉ ๋ก๋๋ 40์ ์ปค๋ฐ revision ์ ์๊ตฌํ๋ค.
MODEL = "Qwen/Qwen3-0.6B"
REVISION = os.environ.get("QWEN_REV", "main") # ํ์์ 40์ ์ปค๋ฐ ํด์๋ก ๊ณ ์
def load_causal_model_cpu(source: str, revision: str):
"""core.load_causal_model ์ CPU ๋ฒ์ (CUDA ๊ฒ์ฌ/ device_map ์ ๊ฑฐ)."""
common = {"trust_remote_code": False}
if revision and revision != "main":
common["revision"] = revision
config = transformers.AutoConfig.from_pretrained(source, **common)
tokenizer = transformers.AutoTokenizer.from_pretrained(source, **common)
model = transformers.AutoModelForCausalLM.from_pretrained(
source,
config=config,
dtype=torch.float32, # CPU ์์ ์ฑ ์ฐ์
low_cpu_mem_usage=True,
**common,
)
model.eval()
metadata = {
"source": source,
"revision": revision,
"dtype": "float32",
"device": "cpu",
"torch_version": torch.__version__,
"transformers_version": transformers.__version__,
}
return model, tokenizer, metadata
def main():
print(f"[load] {MODEL} @ {REVISION} (CPU / float32)")
t0 = time.time()
model, tokenizer, meta = load_causal_model_cpu(MODEL, REVISION)
print(f"[load] done in {time.time()-t0:.1f}s "
f"(params={sum(p.numel() for p in model.parameters())/1e9:.2f}B, "
f"transformers={transformers.__version__})")
# SemIf ์ ๊ฒฐ์ (row) ์คํค๋ง: state(์ฆ๊ฑฐ) + question(๊ธฐ์ค) + options(2~16๊ฐ)
rows = [
{
"id": "sentiment",
"state": "๋ฐฐ์ก์ด 3์ผ์ด๋ ๋ฆ์๊ณ ๊ณ ๊ฐ์ผํฐ๋ ์ฐ๊ฒฐ๋ ์ ๋์ด์. ์ ๋ง ์ค๋ง์
๋๋ค.",
"question": "Classify the customer's sentiment.",
"options": [
{"id": "positive", "description": "Positive / satisfied"},
{"id": "neutral", "description": "Neutral"},
{"id": "negative", "description": "Negative / dissatisfied"},
],
},
{
"id": "route",
"state": "I was double charged and need a refund before Friday.",
"question": "Which team should handle this ticket?",
"options": [
{"id": "billing", "description": "Billing / payments"},
{"id": "tech", "description": "Technical support"},
{"id": "sales", "description": "Sales"},
],
},
]
for row in rows:
print(f"\n=== decision: {row['id']} ===")
r = direct_score(model, tokenizer, row, meta)
pairs = sorted(zip(r["option_ids"], r["probabilities"]),
key=lambda x: -x[1])
winner = pairs[0][0]
print(f" โ ์ ํ: {winner}")
for oid, p in pairs:
bar = "โ" * int(p * 30)
print(f" {oid:10s} {p*100:5.1f}% {bar}")
print(f" (forward {r['forward_seconds']:.1f}s, {r['input_tokens']} tok, "
f"readout: {r['readout']})")
if __name__ == "__main__":
main()
|