Skip to content

Commit e41d861

Browse files
committed
Add separated unit tests
1 parent 88accf4 commit e41d861

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

tests/models/dac/test_modeling_dac.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DacFeatureExtractor, DacModel } from "../../../src/transformers.js";
1+
import { DacFeatureExtractor, DacModel, DacEncoderModel, DacDecoderModel } from "../../../src/transformers.js";
22

33
import { MAX_MODEL_LOAD_TIME, MAX_TEST_EXECUTION_TIME, MAX_MODEL_DISPOSE_TIME, DEFAULT_MODEL_OPTIONS } from "../../init.js";
44

@@ -42,4 +42,47 @@ export default () => {
4242
await model?.dispose();
4343
}, MAX_MODEL_DISPOSE_TIME);
4444
});
45+
46+
describe("DacEncoderModel and DacDecoderModel", () => {
47+
const model_id = "hf-internal-testing/tiny-random-DacModel";
48+
49+
/** @type {DacEncoderModel} */
50+
let encoder_model;
51+
/** @type {DacDecoderModel} */
52+
let decoder_model;
53+
/** @type {DacFeatureExtractor} */
54+
let feature_extractor;
55+
let inputs;
56+
let encoder_outputs;
57+
58+
beforeAll(async () => {
59+
encoder_model = await DacEncoderModel.from_pretrained(model_id, DEFAULT_MODEL_OPTIONS);
60+
decoder_model = await DacDecoderModel.from_pretrained(model_id, DEFAULT_MODEL_OPTIONS);
61+
feature_extractor = await DacFeatureExtractor.from_pretrained(model_id);
62+
inputs = await feature_extractor(new Float32Array(12000));
63+
}, MAX_MODEL_LOAD_TIME);
64+
65+
it(
66+
"encode",
67+
async () => {
68+
encoder_outputs = await encoder_model(inputs);
69+
expect(encoder_outputs.audio_codes.dims).toEqual([1, encoder_model.config.n_codebooks, 37]);
70+
},
71+
MAX_TEST_EXECUTION_TIME,
72+
);
73+
74+
it(
75+
"decode",
76+
async () => {
77+
const { audio_values } = await decoder_model(encoder_outputs);
78+
expect(audio_values.dims).toEqual([1, 1, 11832]);
79+
},
80+
MAX_TEST_EXECUTION_TIME,
81+
);
82+
83+
afterAll(async () => {
84+
await encoder_model?.dispose();
85+
await decoder_model?.dispose();
86+
}, MAX_MODEL_DISPOSE_TIME);
87+
});
4588
};

tests/models/mimi/test_modeling_mimi.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EncodecFeatureExtractor, MimiModel } from "../../../src/transformers.js";
1+
import { EncodecFeatureExtractor, MimiModel, MimiEncoderModel, MimiDecoderModel } from "../../../src/transformers.js";
22

33
import { MAX_MODEL_LOAD_TIME, MAX_TEST_EXECUTION_TIME, MAX_MODEL_DISPOSE_TIME, DEFAULT_MODEL_OPTIONS } from "../../init.js";
44

@@ -42,4 +42,47 @@ export default () => {
4242
await model?.dispose();
4343
}, MAX_MODEL_DISPOSE_TIME);
4444
});
45+
46+
describe("MimiEncoderModel and MimiDecoderModel", () => {
47+
const model_id = "hf-internal-testing/tiny-random-MimiModel";
48+
49+
/** @type {MimiEncoderModel} */
50+
let encoder_model;
51+
/** @type {MimiDecoderModel} */
52+
let decoder_model;
53+
/** @type {EncodecFeatureExtractor} */
54+
let feature_extractor;
55+
let inputs;
56+
let encoder_outputs;
57+
58+
beforeAll(async () => {
59+
encoder_model = await MimiEncoderModel.from_pretrained(model_id, DEFAULT_MODEL_OPTIONS);
60+
decoder_model = await MimiDecoderModel.from_pretrained(model_id, DEFAULT_MODEL_OPTIONS);
61+
feature_extractor = await EncodecFeatureExtractor.from_pretrained(model_id);
62+
inputs = await feature_extractor(new Float32Array(12000));
63+
}, MAX_MODEL_LOAD_TIME);
64+
65+
it(
66+
"encode",
67+
async () => {
68+
encoder_outputs = await encoder_model(inputs);
69+
expect(encoder_outputs.audio_codes.dims).toEqual([1, encoder_model.config.num_quantizers, 7]);
70+
},
71+
MAX_TEST_EXECUTION_TIME,
72+
);
73+
74+
it(
75+
"decode",
76+
async () => {
77+
const { audio_values } = await decoder_model(encoder_outputs);
78+
expect(audio_values.dims).toEqual([1, 1, 13440]);
79+
},
80+
MAX_TEST_EXECUTION_TIME,
81+
);
82+
83+
afterAll(async () => {
84+
await encoder_model?.dispose();
85+
await decoder_model?.dispose();
86+
}, MAX_MODEL_DISPOSE_TIME);
87+
});
4588
};

0 commit comments

Comments
 (0)