Spaces:
Running
on
Zero
Running
on
Zero
app.py
CHANGED
@@ -20,14 +20,13 @@ except ImportError:
|
|
20 |
return decorator
|
21 |
spaces = type('spaces', (), {'GPU': spaces_gpu_decorator})
|
22 |
|
23 |
-
# Model configuration -
|
24 |
MODEL_NAME = "fdtn-ai/Foundation-Sec-8B"
|
25 |
-
#MODEL_NAME = "sshleifer/tiny-gpt2"
|
26 |
|
27 |
# Initialize tokenizer and model using pipeline approach
|
28 |
print(f"Loading model: {MODEL_NAME}")
|
29 |
try:
|
30 |
-
print(f"Initializing
|
31 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
32 |
text_pipeline = pipeline(
|
33 |
"text-generation",
|
@@ -37,14 +36,14 @@ try:
|
|
37 |
device_map="auto",
|
38 |
trust_remote_code=True
|
39 |
)
|
40 |
-
print(f"
|
41 |
|
42 |
# Extract model and tokenizer from pipeline for direct access
|
43 |
model = text_pipeline.model
|
44 |
tok = text_pipeline.tokenizer
|
45 |
|
46 |
except Exception as e:
|
47 |
-
print(f"Error initializing model
|
48 |
print("Trying with simplified parameters...")
|
49 |
|
50 |
try:
|
@@ -56,36 +55,11 @@ except Exception as e:
|
|
56 |
)
|
57 |
model = text_pipeline.model
|
58 |
tok = text_pipeline.tokenizer
|
59 |
-
print(f"
|
60 |
|
61 |
except Exception as e2:
|
62 |
-
print(f"
|
63 |
-
|
64 |
-
|
65 |
-
# Use distilgpt2 which uses safetensors format and is more compatible
|
66 |
-
MODEL_NAME = "distilgpt2"
|
67 |
-
try:
|
68 |
-
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
69 |
-
text_pipeline = pipeline(
|
70 |
-
"text-generation",
|
71 |
-
model=MODEL_NAME,
|
72 |
-
tokenizer=tokenizer
|
73 |
-
)
|
74 |
-
model = text_pipeline.model
|
75 |
-
tok = text_pipeline.tokenizer
|
76 |
-
print(f"Fallback model loaded: {MODEL_NAME}")
|
77 |
-
|
78 |
-
except Exception as e3:
|
79 |
-
print(f"Fallback also failed: {str(e3)}")
|
80 |
-
print("Trying direct model loading as last resort...")
|
81 |
-
|
82 |
-
# Last resort: direct loading without pipeline
|
83 |
-
try:
|
84 |
-
tok = AutoTokenizer.from_pretrained(MODEL_NAME)
|
85 |
-
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME).eval()
|
86 |
-
print(f"Direct loading successful: {MODEL_NAME}")
|
87 |
-
except Exception as e4:
|
88 |
-
raise RuntimeError(f"All model loading attempts failed. Last error: {str(e4)}")
|
89 |
|
90 |
# Log device information
|
91 |
if hasattr(model, 'device'):
|
|
|
20 |
return decorator
|
21 |
spaces = type('spaces', (), {'GPU': spaces_gpu_decorator})
|
22 |
|
23 |
+
# Model configuration - Foundation-Sec-8B only
|
24 |
MODEL_NAME = "fdtn-ai/Foundation-Sec-8B"
|
|
|
25 |
|
26 |
# Initialize tokenizer and model using pipeline approach
|
27 |
print(f"Loading model: {MODEL_NAME}")
|
28 |
try:
|
29 |
+
print(f"Initializing Foundation-Sec-8B model...")
|
30 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
31 |
text_pipeline = pipeline(
|
32 |
"text-generation",
|
|
|
36 |
device_map="auto",
|
37 |
trust_remote_code=True
|
38 |
)
|
39 |
+
print(f"Foundation-Sec-8B model initialized successfully")
|
40 |
|
41 |
# Extract model and tokenizer from pipeline for direct access
|
42 |
model = text_pipeline.model
|
43 |
tok = text_pipeline.tokenizer
|
44 |
|
45 |
except Exception as e:
|
46 |
+
print(f"Error initializing Foundation-Sec-8B model: {str(e)}")
|
47 |
print("Trying with simplified parameters...")
|
48 |
|
49 |
try:
|
|
|
55 |
)
|
56 |
model = text_pipeline.model
|
57 |
tok = text_pipeline.tokenizer
|
58 |
+
print(f"Foundation-Sec-8B model loaded with simplified parameters")
|
59 |
|
60 |
except Exception as e2:
|
61 |
+
print(f"Failed to load Foundation-Sec-8B model: {str(e2)}")
|
62 |
+
raise RuntimeError(f"Could not load Foundation-Sec-8B model. Please ensure the model is accessible and try again. Error: {str(e2)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
# Log device information
|
65 |
if hasattr(model, 'device'):
|