Safetensors
GGUF
English
materials-science
computational-materials
materials-analysis
property-prediction
materials-discovery
crystal-structure
band-gap-prediction
thermal-properties
mechanical-properties
electronic-properties
materials-informatics
scientific-ai
chain-of-thought
structured-output
reasoning
materials-characterization
formation-energy-analysis
thermodynamic-stability
materials-optimization
predictive-modeling
materials-classification
structure-property-correlation
semiconductor-analysis
high-temperature-materials
power-electronics-materials
materials-screening
research-grade-analysis
industry-applications
MaterialsAnalyst-AI-7B
MaterialsAnalyst-AI
MaterialsAnalyst
materials-engineering
computational-chemistry
solid-state-physics
materials-design
materials-data-analysis
crystallography
materials-simulation
materials-research
advanced-materials
nanomaterials
functional-materials
energy-materials
catalysis-materials
materials-database
materials-prediction
materials-ai
chemoinformatics
physics-informed-ai
scientific-machine-learning
materials-genome
Upload 2 files
Browse files
Scripts/Inference_llama.cpp.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llama_cpp import Llama
|
| 2 |
+
|
| 3 |
+
# INSTRUCTIONS: Replace the JSON below with your material's properties
|
| 4 |
+
# Common data sources: materialsproject.org, DFT calculations, experimental databases
|
| 5 |
+
|
| 6 |
+
JSON_INPUT = """
|
| 7 |
+
{
|
| 8 |
+
"material_id": "mp-8062",
|
| 9 |
+
"formula": "SiC",
|
| 10 |
+
"elements": [
|
| 11 |
+
"Si",
|
| 12 |
+
"C"
|
| 13 |
+
],
|
| 14 |
+
"spacegroup": "P63mc",
|
| 15 |
+
"band_gap": 3.26,
|
| 16 |
+
"formation_energy_per_atom": -0.73,
|
| 17 |
+
"density": 3.21,
|
| 18 |
+
"volume": 41.2,
|
| 19 |
+
"nsites": 8,
|
| 20 |
+
"is_stable": true,
|
| 21 |
+
"elastic_modulus": 448,
|
| 22 |
+
"bulk_modulus": 220,
|
| 23 |
+
"thermal_expansion": 4.2e-06,
|
| 24 |
+
"electron_affinity": 4.0,
|
| 25 |
+
"ionization_energy": 6.7,
|
| 26 |
+
"crystal_system": "Hexagonal",
|
| 27 |
+
"magnetic_property": "Non-magnetic",
|
| 28 |
+
"thermal_conductivity": 490,
|
| 29 |
+
"specific_heat": 0.69,
|
| 30 |
+
"is_superconductor": false,
|
| 31 |
+
"band_gap_type": "Indirect"
|
| 32 |
+
}
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
model_path = "./" # Path to the directory containing your model weight files
|
| 36 |
+
|
| 37 |
+
llm = Llama(
|
| 38 |
+
model_path=model_path,
|
| 39 |
+
n_gpu_layers=29,
|
| 40 |
+
n_ctx=10000,
|
| 41 |
+
n_threads=4
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
topic = JSON_INPUT.strip()
|
| 45 |
+
prompt = f"USER: {topic}\nASSISTANT:"
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
output = llm(
|
| 49 |
+
prompt,
|
| 50 |
+
max_tokens=3000,
|
| 51 |
+
temperature=0.7,
|
| 52 |
+
top_p=0.9,
|
| 53 |
+
repeat_penalty=1.1
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
result = output.get("choices", [{}])[0].get("text", "").strip()
|
| 57 |
+
|
| 58 |
+
print(result)
|
| 59 |
+
|
| 60 |
+
|
Scripts/Inference_safetensors.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
# INSTRUCTIONS: Replace the JSON below with your material's properties
|
| 5 |
+
# Common data sources: materialsproject.org, DFT calculations, experimental databases
|
| 6 |
+
|
| 7 |
+
JSON_INPUT = """
|
| 8 |
+
{
|
| 9 |
+
"material_id": "mp-8062",
|
| 10 |
+
"formula": "SiC",
|
| 11 |
+
"elements": [
|
| 12 |
+
"Si",
|
| 13 |
+
"C"
|
| 14 |
+
],
|
| 15 |
+
"spacegroup": "P63mc",
|
| 16 |
+
"band_gap": 3.26,
|
| 17 |
+
"formation_energy_per_atom": -0.73,
|
| 18 |
+
"density": 3.21,
|
| 19 |
+
"volume": 41.2,
|
| 20 |
+
"nsites": 8,
|
| 21 |
+
"is_stable": true,
|
| 22 |
+
"elastic_modulus": 448,
|
| 23 |
+
"bulk_modulus": 220,
|
| 24 |
+
"thermal_expansion": 4.2e-06,
|
| 25 |
+
"electron_affinity": 4.0,
|
| 26 |
+
"ionization_energy": 6.7,
|
| 27 |
+
"crystal_system": "Hexagonal",
|
| 28 |
+
"magnetic_property": "Non-magnetic",
|
| 29 |
+
"thermal_conductivity": 490,
|
| 30 |
+
"specific_heat": 0.69,
|
| 31 |
+
"is_superconductor": false,
|
| 32 |
+
"band_gap_type": "Indirect"
|
| 33 |
+
}
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
def load_model(model_path):
|
| 37 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 38 |
+
model_path,
|
| 39 |
+
torch_dtype=torch.float16,
|
| 40 |
+
device_map="auto",
|
| 41 |
+
trust_remote_code=True
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 45 |
+
model_path,
|
| 46 |
+
trust_remote_code=True
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
return model, tokenizer
|
| 50 |
+
|
| 51 |
+
def generate_response(model, tokenizer, topic):
|
| 52 |
+
topic = topic.strip()
|
| 53 |
+
|
| 54 |
+
prompt = f"USER: {topic}\nASSISTANT:"
|
| 55 |
+
|
| 56 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 57 |
+
|
| 58 |
+
outputs = model.generate(
|
| 59 |
+
**inputs,
|
| 60 |
+
max_new_tokens=3000,
|
| 61 |
+
temperature=0.7,
|
| 62 |
+
top_p=0.9,
|
| 63 |
+
repetition_penalty=1.1,
|
| 64 |
+
do_sample=True
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 68 |
+
|
| 69 |
+
return response.split("ASSISTANT:")[-1].strip()
|
| 70 |
+
|
| 71 |
+
def run():
|
| 72 |
+
model_path = "./" # Path to the directory containing your model weight files
|
| 73 |
+
|
| 74 |
+
model, tokenizer = load_model(model_path)
|
| 75 |
+
|
| 76 |
+
result = generate_response(model, tokenizer, JSON_INPUT)
|
| 77 |
+
|
| 78 |
+
print(result)
|
| 79 |
+
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
run()
|
| 82 |
+
|
| 83 |
+
|