Test
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.venv/
|
||||||
|
.cache/
|
||||||
@@ -1,3 +1,11 @@
|
|||||||
# TFM
|
# TFM
|
||||||
|
|
||||||
Test TFM remote execution on upc server
|
Test TFM remote execution on upc server
|
||||||
|
|
||||||
|
## TODO:
|
||||||
|
|
||||||
|
- Alguna cosa legal per carregar models i fer benchmarking potser
|
||||||
|
- Mirar de com implementar la cosa de busqueda de tensors
|
||||||
|
- Reemplaçarlos allà
|
||||||
|
- Fer posttraining
|
||||||
|
- Profit
|
||||||
|
|||||||
6
benchmark.sh
Normal file
6
benchmark.sh
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
lm_eval
|
||||||
|
--model hf \
|
||||||
|
--model_args pretrained=~/Uni/tfm/qwen_random,dtype=bfloat16,device_mp=auto \
|
||||||
|
--tasks hellaswag,arc_easy,boolq \
|
||||||
|
--batch_size auto
|
||||||
101
requirements.txt
Normal file
101
requirements.txt
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
absl-py==2.4.0
|
||||||
|
accelerate==1.13.0
|
||||||
|
aiohappyeyeballs==2.6.2
|
||||||
|
aiohttp==3.14.1
|
||||||
|
aiosignal==1.4.0
|
||||||
|
annotated-doc==0.0.4
|
||||||
|
anyio==4.13.0
|
||||||
|
attrs==26.1.0
|
||||||
|
certifi==2026.5.20
|
||||||
|
chardet==6.0.0.post1
|
||||||
|
charset-normalizer==3.4.7
|
||||||
|
click==8.4.1
|
||||||
|
colorama==0.4.6
|
||||||
|
cuda-bindings==13.3.1
|
||||||
|
cuda-pathfinder==1.5.5
|
||||||
|
cuda-toolkit==13.0.2
|
||||||
|
DataProperty==1.1.1
|
||||||
|
datasets==5.0.0
|
||||||
|
dill==0.4.1
|
||||||
|
evaluate==0.4.6
|
||||||
|
filelock==3.29.1
|
||||||
|
frozenlist==1.8.0
|
||||||
|
fsspec==2026.4.0
|
||||||
|
h11==0.16.0
|
||||||
|
hf-xet==1.5.1
|
||||||
|
httpcore==1.0.9
|
||||||
|
httpx==0.28.1
|
||||||
|
huggingface_hub==1.18.0
|
||||||
|
idna==3.18
|
||||||
|
Jinja2==3.1.6
|
||||||
|
joblib==1.5.3
|
||||||
|
lm_eval==0.4.12
|
||||||
|
lxml==6.1.1
|
||||||
|
markdown-it-py==4.2.0
|
||||||
|
MarkupSafe==3.0.3
|
||||||
|
mbstrdecoder==1.1.5
|
||||||
|
mdurl==0.1.2
|
||||||
|
more-itertools==11.1.0
|
||||||
|
mpmath==1.3.0
|
||||||
|
multidict==6.7.1
|
||||||
|
multiprocess==0.70.19
|
||||||
|
narwhals==2.22.1
|
||||||
|
networkx==3.6.1
|
||||||
|
nltk==3.9.4
|
||||||
|
numpy==2.4.6
|
||||||
|
nvidia-cublas==13.1.1.3
|
||||||
|
nvidia-cuda-cupti==13.0.85
|
||||||
|
nvidia-cuda-nvrtc==13.0.88
|
||||||
|
nvidia-cuda-runtime==13.0.96
|
||||||
|
nvidia-cudnn-cu13==9.20.0.48
|
||||||
|
nvidia-cufft==12.0.0.61
|
||||||
|
nvidia-cufile==1.15.1.6
|
||||||
|
nvidia-curand==10.4.0.35
|
||||||
|
nvidia-cusolver==12.0.4.66
|
||||||
|
nvidia-cusparse==12.6.3.3
|
||||||
|
nvidia-cusparselt-cu13==0.8.1
|
||||||
|
nvidia-nccl-cu13==2.29.7
|
||||||
|
nvidia-nvjitlink==13.0.88
|
||||||
|
nvidia-nvshmem-cu13==3.4.5
|
||||||
|
nvidia-nvtx==13.0.85
|
||||||
|
packaging==26.2
|
||||||
|
pandas==3.0.3
|
||||||
|
pathvalidate==3.3.1
|
||||||
|
portalocker==3.2.0
|
||||||
|
propcache==0.5.2
|
||||||
|
psutil==7.2.2
|
||||||
|
pyarrow==24.0.0
|
||||||
|
Pygments==2.20.0
|
||||||
|
pytablewriter==1.2.1
|
||||||
|
python-dateutil==2.9.0.post0
|
||||||
|
pytz==2026.2
|
||||||
|
PyYAML==6.0.3
|
||||||
|
regex==2026.5.9
|
||||||
|
requests==2.34.2
|
||||||
|
rich==15.0.0
|
||||||
|
rouge_score==0.1.2
|
||||||
|
sacrebleu==2.6.0
|
||||||
|
safetensors==0.8.0
|
||||||
|
scikit-learn==1.9.0
|
||||||
|
scipy==1.17.1
|
||||||
|
setuptools==81.0.0
|
||||||
|
shellingham==1.5.4
|
||||||
|
six==1.17.0
|
||||||
|
sqlitedict==2.1.0
|
||||||
|
sympy==1.14.0
|
||||||
|
tabledata==1.3.5
|
||||||
|
tabulate==0.10.0
|
||||||
|
tcolorpy==0.1.7
|
||||||
|
threadpoolctl==3.6.0
|
||||||
|
tokenizers==0.22.2
|
||||||
|
torch==2.12.0
|
||||||
|
tqdm==4.68.2
|
||||||
|
transformers==5.10.2
|
||||||
|
triton==3.7.0
|
||||||
|
typepy==1.3.5
|
||||||
|
typer==0.25.1
|
||||||
|
typing_extensions==4.15.0
|
||||||
|
urllib3==2.7.0
|
||||||
|
word2number==1.1
|
||||||
|
xxhash==3.7.0
|
||||||
|
yarl==1.24.2
|
||||||
65
test.py
Normal file
65
test.py
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import torch
|
||||||
|
import torch.nn as nn
|
||||||
|
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||||||
|
|
||||||
|
model_id = "Qwen/Qwen3.5-0.8B"
|
||||||
|
cache_path = "./.cache"
|
||||||
|
|
||||||
|
# Load tokenizer + model
|
||||||
|
tokenizer = AutoTokenizer.from_pretrained(model_id, cache_dir=cache_path)
|
||||||
|
|
||||||
|
model = AutoModelForCausalLM.from_pretrained(
|
||||||
|
model_id,
|
||||||
|
torch_dtype=torch.bfloat16,
|
||||||
|
device_map="auto",
|
||||||
|
cache_dir=cache_path,
|
||||||
|
)
|
||||||
|
|
||||||
|
model.eval()
|
||||||
|
print(model)
|
||||||
|
|
||||||
|
# -----------------------------
|
||||||
|
# 1. Replace ALL linear layers
|
||||||
|
# -----------------------------
|
||||||
|
def replace_weights_with_random(module):
|
||||||
|
for name, child in module.named_children():
|
||||||
|
|
||||||
|
# If it's a Linear layer, replace weights
|
||||||
|
if isinstance(child, nn.Linear):
|
||||||
|
with torch.no_grad():
|
||||||
|
child.weight.copy_(
|
||||||
|
torch.randn_like(child.weight)
|
||||||
|
)
|
||||||
|
if child.bias is not None:
|
||||||
|
child.bias.copy_(
|
||||||
|
torch.randn_like(child.bias)
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# recurse into submodules
|
||||||
|
replace_weights_with_random(child)
|
||||||
|
|
||||||
|
replace_weights_with_random(model)
|
||||||
|
|
||||||
|
print("All linear layer weights replaced with random tensors.")
|
||||||
|
|
||||||
|
# -----------------------------
|
||||||
|
# 2. Run inference
|
||||||
|
# -----------------------------
|
||||||
|
prompt = "Explain tensor networks in simple terms."
|
||||||
|
|
||||||
|
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
||||||
|
|
||||||
|
with torch.no_grad():
|
||||||
|
output = model.generate(
|
||||||
|
**inputs,
|
||||||
|
max_new_tokens=500,
|
||||||
|
temperature=1.0,
|
||||||
|
do_sample=True
|
||||||
|
)
|
||||||
|
|
||||||
|
print("\n=== OUTPUT ===\n")
|
||||||
|
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
||||||
|
|
||||||
|
model.save_pretrained("./.cache/qwen_random")
|
||||||
|
tokenizer.save_pretrained("./.cache/qwen_random")
|
||||||
Reference in New Issue
Block a user