Skip to content

Commit

Permalink
Merge pull request #712 from permaweb/twilson63/feat-aos64-llm
Browse files Browse the repository at this point in the history
feat: add resizeHeap to Module
  • Loading branch information
twilson63 authored May 14, 2024
2 parents 7cc50da + 3b3eeda commit dff3d57
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
6 changes: 4 additions & 2 deletions loader/src/formats/wasm64-emscripten.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5422,8 +5422,12 @@ var Module = (() => {

run();



moduleRtn = readyPromise;

Module.resizeHeap = _emscripten_resize_heap;

for (const prop of Object.keys(Module)) {
if (!(prop in moduleArg)) {
Object.defineProperty(moduleArg, prop, {
Expand All @@ -5435,8 +5439,6 @@ var Module = (() => {
}
}

moduleRtn.resizeHeap = _emscripten_resize_heap;

return moduleRtn;
}
);
Expand Down
5 changes: 4 additions & 1 deletion loader/src/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ module.exports = async function (binary, options) {
/** end mock console.log */

if (buffer) {
if (instance.HEAPU8.byteLength < buffer.byteLength) instance.resizeHeap(buffer.byteLength)
if (instance.HEAPU8.byteLength < buffer.byteLength) {
console.log("RESIZE HEAP")
instance.resizeHeap(buffer.byteLength)
}
instance.HEAPU8.set(buffer)
}
/**
Expand Down
38 changes: 28 additions & 10 deletions loader/test/aos64/aos64.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ console.log(`${MODULE_PATH}`)
const wasmBinary = fs.readFileSync('./test/aos64/aos64.wasm')

test.skip('AOS-Llama+VFS Tests', async () => {
const { default: AoLoader } = await import(MODULE_PATH)
const handle = await AoLoader(wasmBinary, {
const { default: AoLoader } = await import('../../src/index.cjs')

const handle = await AoLoader((imports, cb) =>
WebAssembly.instantiate(wasmBinary, imports).then((result) => cb(result.instance)), {
format: 'wasm64-unknown-emscripten-draft_2024_02_15',
WeaveDrive: weaveDrive,
admissableList: [
Expand All @@ -27,22 +29,41 @@ test.skip('AOS-Llama+VFS Tests', async () => {
ARWEAVE: 'https://arweave.net',
mode: "test",
blockHeight: 100,

spawn: {
"Scheduler": "TEST_SCHED_ADDR"
},

process: {
id: "TEST_PROCESS_ID",
owner: "TEST_PROCESS_OWNER",
tags: [
{ name: "Extension", value: "Weave-Drive" }
]
}
})

const r = await handle(null,
{
Id: 'FOO',
Owner: 'tom',
Target: 'AOS',
Tags: [
{ name: 'Action', value: 'Eval' }
],
Data: `
Llama = require('llama')
Llama.load('/data/ISrbGzQot05rs_HKC08O_SmkipYQnqgB1yC3mjZZeEo')
Llama.setPrompt([[<|user|>Tell me a great story<|assistant|>]])
`,
Module: '1234',
['Block-Height']: '1000'
},
{
Process: { Id: 'ctr-id-456', Tags: [] }
}
)
//console.log(result.Output)

})
const result = await handle(null,
const result = await handle(r.Memory,
{
Id: 'FOO',
Owner: 'tom',
Expand All @@ -52,10 +73,7 @@ test.skip('AOS-Llama+VFS Tests', async () => {
],
Data: `
local result = ""
local Llama = require('llama')
Llama.load('/data/M-OzkyjxWhSvWYF87p0kvmkuAEEkvOzIj4nMNoSIydc')
Llama.setPrompt([[<|user|>Tell me a great story<|assistant|>]])
for i = 0, 10, 1 do
for i = 0, 100, 1 do
local token = Llama.next()
result = result .. token
end
Expand Down

0 comments on commit dff3d57

Please sign in to comment.