Downloads · 30 days
603
11% of all-time downloads
AstroMLab/AstroSage-8B-GGUF
AstroSage-8B-GGUF is a text generation model from AstroMLab. Use it when you need the model to write or continue text.
Downloads · 30 days
603
11% of all-time downloads
All-time downloads
5.3K
Public
Repo size
24.6 GB
Likes
4
Public
Click a slice to open those files.
.gguf24.6 GB · 100%
From the Hugging Face model README
https://arxiv.org/abs/2411.09012
AstroSage-Llama-3.1-8B-GGUF is the quantized version of AstroSage-Llama-3.1-8B, optimized for efficient deployment while maintaining the model's specialized capabilities in astronomy, astrophysics, and cosmology. This quantized version aims to provide a more accessible deployment option while preserving the model's capabilities.
from llama_cpp import Llama
from huggingface_hub import hf_hub_download
import os
import sys
import contextlib
# Suppress warnings
@contextlib.contextmanager
def suppress_stderr():
stderr = sys.stderr
with open(os.devnull, 'w') as devnull:
sys.stderr = devnull
try:
yield
finally:
sys.stderr = stderr
# or change the filename to AstroSage-8B-BF16.gguf for BF16 quantization
def download_model(repo_id="AstroMLab/AstroSage-8B-GGUF", filename="AstroSage-8B-Q8_0.gguf"):
try:
os.makedirs("models", exist_ok=True)
local_path = os.path.join("models", filename)
if not os.path.exists(local_path):
print(f"Downloading {filename}...")
with suppress_stderr():
local_path = hf_hub_download(
repo_id=repo_id,
filename=filename,
local_dir="models",
local_dir_use_symlinks=False
)
print("Download complete!")
return local_path
except Exception as e:
print(f"Error downloading model: {e}")
raise
def initialize_llm():
model_path = download_model()
with suppress_stderr():
return Llama(
model_path=model_path,
n_ctx=2048,
n_threads=4
)
def get_response(llm, prompt, max_tokens=128):
response = llm(
prompt,
max_tokens=max_tokens,
temperature=0.7,
top_p=0.9,
top_k=40,
repeat_penalty=1.1,
stop=["User:", "\n\n"]
)
return response['choices'][0]['text']
def main():
llm = initialize_llm()
# Example question about galaxy formation
first_question = "How does a galaxy form?"
print("\nQuestion:", first_question)
print("\nAI:", get_response(llm, first_question).strip(), "\n")
print("\nYou can now ask more questions! Type 'quit' or 'exit' to end the conversation.\n")
while True:
try:
user_input = input("You: ")
if user_input.lower() in ['quit', 'exit']:
print("\nGoodbye!")
break
print("\nAI:", get_response(llm, user_input).strip(), "\n")
except KeyboardInterrupt:
print("\nGoodbye!")
break
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()
pip install llama-cpp-python huggingface_hub
For Macbook with Apple Silicon, install llama-cpp with the following instead
CMAKE_ARGS="-DCMAKE_OSX_ARCHITECTURES=arm64 -DLLAMA_METAL=on" pip install llama-cpp-python
n_ctx: Context window size (default: 2048)n_threads: Number of CPU threads to use (adjust based on your hardware)temperature: Controls randomnesstop_p: Nucleus sampling parametertop_k: Limits vocabulary choicesrepeat_penalty: Prevents repetitionmax_tokens: Maximum length of response (128 default, increase for longer answers)The model will automatically:
For different use cases, you can:
The quantized model offers several advantages:
Note: Formal benchmarking of the quantized model is pending. Performance metrics will be updated once comprehensive testing is completed.
While this model is designed for scientific use:
@preprint{dehaan2024astromlab3,
title={AstroMLab 3: Achieving GPT-4o Level Performance in Astronomy with a Specialized 8B-Parameter Large Language Model},
author={Tijmen de Haan and Yuan-Sen Ting and Tirthankar Ghosal and Tuan Dung Nguyen and Alberto Accomazzi and Azton Wells and Nesar Ramachandra and Rui Pan and Zechang Sun},
year={2024},
eprint={2411.09012},
archivePrefix={arXiv},
primaryClass={astro-ph.IM},
url={https://arxiv.org/abs/2411.09012},
}
Additional note: When citing this quantized version, please reference both the original AstroMLab 3 paper above and specify the use of the GGUF quantized variant.