File size: 1,712 Bytes
d7c00f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Janus Model Test Script
// Test if the model can be loaded successfully

import { AutoProcessor, MultiModalityCausalLM } from "@huggingface/transformers";

async function testJanusModel() {
    console.log("Testing Janus Model Loading...");

    const modelPath =  + str(model_dir) + ;

    try {
        console.log("Loading processor...");
        const processor = await AutoProcessor.from_pretrained(modelPath);
        console.log("Processor loaded successfully");

        console.log("Loading model...");
        const model = await MultiModalityCausalLM.from_pretrained(modelPath, {
            device: "webgpu",
            dtype: "q4f16"
        });
        console.log("Model loaded successfully");

        console.log("
SUCCESS! Model initialization complete");
        console.log("Model is ready for inference");

        return { model, processor };

    } catch (error) {
        console.error("Model loading failed:");
        console.error(error);

        // Try CPU fallback
        console.log("
Trying CPU fallback...");
        try {
            const processor = await AutoProcessor.from_pretrained(modelPath);
            const model = await MultiModalityCausalLM.from_pretrained(modelPath, {
                device: "cpu"
            });
            console.log("CPU fallback successful");
            return { model, processor };
        } catch (cpuError) {
            console.error("CPU fallback also failed:");
            console.error(cpuError);
            throw cpuError;
        }
    }
}

// Run the test
testJanusModel()
    .then(() => console.log("
Test completed successfully"))
    .catch(error => console.error("
Test failed:", error));

export { testJanusModel };