forked from huggingface/transformers.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Helium and Glm (huggingface#1156)
* Add support for Helium and Glm * Add unit tests * Remove duplicate definitions
- Loading branch information
Showing
6 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { PreTrainedTokenizer, GlmForCausalLM } from "../../../src/transformers.js"; | ||
|
||
import { MAX_MODEL_LOAD_TIME, MAX_TEST_EXECUTION_TIME, MAX_MODEL_DISPOSE_TIME, DEFAULT_MODEL_OPTIONS } from "../../init.js"; | ||
|
||
export default () => { | ||
describe("GlmForCausalLM", () => { | ||
const model_id = "hf-internal-testing/tiny-random-GlmForCausalLM"; | ||
/** @type {GlmForCausalLM} */ | ||
let model; | ||
/** @type {PreTrainedTokenizer} */ | ||
let tokenizer; | ||
beforeAll(async () => { | ||
model = await GlmForCausalLM.from_pretrained(model_id, DEFAULT_MODEL_OPTIONS); | ||
tokenizer = await PreTrainedTokenizer.from_pretrained(model_id); | ||
tokenizer.padding_side = "left"; | ||
}, MAX_MODEL_LOAD_TIME); | ||
|
||
it( | ||
"batch_size=1", | ||
async () => { | ||
const inputs = tokenizer("hello"); | ||
const outputs = await model.generate({ | ||
...inputs, | ||
max_length: 10, | ||
}); | ||
expect(outputs.tolist()).toEqual([[23582n, 5797n, 38238n, 24486n, 36539n, 34489n, 6948n, 34489n, 6948n, 16014n]]); | ||
}, | ||
MAX_TEST_EXECUTION_TIME, | ||
); | ||
|
||
it( | ||
"batch_size>1", | ||
async () => { | ||
const inputs = tokenizer(["hello", "hello world"], { padding: true }); | ||
const outputs = await model.generate({ | ||
...inputs, | ||
max_length: 10, | ||
}); | ||
expect(outputs.tolist()).toEqual([ | ||
[59246n, 23582n, 5797n, 38238n, 24486n, 36539n, 34489n, 6948n, 34489n, 6948n], | ||
[23582n, 2901n, 39936n, 25036n, 55411n, 10337n, 3424n, 39183n, 30430n, 37285n], | ||
]); | ||
}, | ||
MAX_TEST_EXECUTION_TIME, | ||
); | ||
|
||
afterAll(async () => { | ||
await model?.dispose(); | ||
}, MAX_MODEL_DISPOSE_TIME); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { PreTrainedTokenizer, HeliumForCausalLM } from "../../../src/transformers.js"; | ||
|
||
import { MAX_MODEL_LOAD_TIME, MAX_TEST_EXECUTION_TIME, MAX_MODEL_DISPOSE_TIME, DEFAULT_MODEL_OPTIONS } from "../../init.js"; | ||
|
||
export default () => { | ||
describe("HeliumForCausalLM", () => { | ||
const model_id = "hf-internal-testing/tiny-random-HeliumForCausalLM"; | ||
/** @type {HeliumForCausalLM} */ | ||
let model; | ||
/** @type {PreTrainedTokenizer} */ | ||
let tokenizer; | ||
beforeAll(async () => { | ||
model = await HeliumForCausalLM.from_pretrained(model_id, DEFAULT_MODEL_OPTIONS); | ||
tokenizer = await PreTrainedTokenizer.from_pretrained(model_id); | ||
tokenizer.padding_side = "left"; | ||
}, MAX_MODEL_LOAD_TIME); | ||
|
||
it( | ||
"batch_size=1", | ||
async () => { | ||
const inputs = tokenizer("hello"); | ||
const outputs = await model.generate({ | ||
...inputs, | ||
max_length: 10, | ||
}); | ||
expect(outputs.tolist()).toEqual([[1n, 456n, 5660n, 1700n, 1486n, 37744n, 35669n, 39396n, 12024n, 32253n]]); | ||
}, | ||
MAX_TEST_EXECUTION_TIME, | ||
); | ||
|
||
it( | ||
"batch_size>1", | ||
async () => { | ||
const inputs = tokenizer(["hello", "hello world"], { padding: true }); | ||
const outputs = await model.generate({ | ||
...inputs, | ||
max_length: 10, | ||
}); | ||
expect(outputs.tolist()).toEqual([ | ||
[3n, 1n, 456n, 5660n, 1700n, 1486n, 37744n, 35669n, 39396n, 12024n], | ||
[1n, 456n, 5660n, 998n, 6136n, 2080n, 172n, 8843n, 40579n, 23953n], | ||
]); | ||
}, | ||
MAX_TEST_EXECUTION_TIME, | ||
); | ||
|
||
afterAll(async () => { | ||
await model?.dispose(); | ||
}, MAX_MODEL_DISPOSE_TIME); | ||
}); | ||
}; |