fixed hugging face llm

pull/390/head
vyomakesh09 11 months ago
parent fe5c446ac2
commit 10028916ee

@ -1,18 +1,29 @@
from swarms.models import HuggingfaceLLM from swarms.models import HuggingfaceLLM
import torch
# Initialize with custom configuration try:
custom_config = { inference = HuggingfaceLLM(
"quantize": True, model_id="gpt2",
"quantization_config": {"load_in_4bit": True}, quantize=False,
"verbose": True, verbose=True,
} )
inference = HuggingfaceLLM(
model_id="NousResearch/Nous-Hermes-2-Vision-Alpha", **custom_config
)
# Generate text based on a prompt device = "cuda" if torch.cuda.is_available() else "cpu"
prompt_text = ( inference.model.to(device)
"Create a list of known biggest risks of structural collapse with references"
) prompt_text = "Create a list of known biggest risks of structural collapse with references"
generated_text = inference(prompt_text) inputs = inference.tokenizer(prompt_text, return_tensors="pt").to(device)
print(generated_text)
generated_ids = inference.model.generate(
**inputs,
max_new_tokens=1000, # Adjust the length of the generation
temperature=0.7, # Adjust creativity
top_k=50, # Limits the vocabulary considered at each step
pad_token_id=inference.tokenizer.eos_token_id,
do_sample=True # Enable sampling to utilize temperature
)
generated_text = inference.tokenizer.decode(generated_ids[0], skip_special_tokens=True)
print(generated_text)
except Exception as e:
print(f"An error occurred: {e}")

Loading…
Cancel
Save