Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: Maximum call stack size exceeded for image buffer input #247

Closed
zeke opened this issue Apr 28, 2024 · 9 comments
Closed

RangeError: Maximum call stack size exceeded for image buffer input #247

zeke opened this issue Apr 28, 2024 · 9 comments

Comments

@zeke
Copy link
Member

zeke commented Apr 28, 2024

I've got this code:

import Replicate from 'replicate'

const replicate = new Replicate()

const model = 'yorickvp/llava-v1.6-34b:41ecfbfb261e6c1adf3ad896c9066ca98346996d7c4045c5bc944a79d430f174'

export default async function describeImage (imageBuffer) {
  const input = {
    image: imageBuffer,
    prompt: "What's happening in this image?"
  }
  const output = await replicate.run(model, { input })
  return output
}

And this image:

IMG_1700

I'm trying to feed this image to https://replicate.com/yorickvp/llava-v1.6-34b as a buffer:

const buffer = await readFile(imagePath)
console.log({ buffer })
{
  buffer: <Buffer ff d8 ff e1 01 08 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 12 00 03 00 00 00 01 00 01 00 00 01 1a 00 05 00 00 00 01 00 00 00 56 01 1b 00 05 ... 401476 more bytes>
}

But I'm getting this error:

Error processing images: RangeError: Maximum call stack size exceeded
    at bytesToBase64 (/Users/z/Desktop/los-angeles/node_modules/replicate/lib/util.js:136:35)
    at /Users/z/Desktop/los-angeles/node_modules/replicate/lib/util.js:245:18
    at transform (/Users/z/Desktop/los-angeles/node_modules/replicate/lib/util.js:272:16)
    at transform (/Users/z/Desktop/los-angeles/node_modules/replicate/lib/util.js:267:25)
    at transformFileInputs (/Users/z/Desktop/los-angeles/node_modules/replicate/lib/util.js:219:24)
    at Replicate.createPrediction (/Users/z/Desktop/los-angeles/node_modules/replicate/lib/predictions.js:33:22)
    at Replicate.run (/Users/z/Desktop/los-angeles/node_modules/replicate/index.js:138:43)
    at describeImage (file:///Users/z/Desktop/los-angeles/describe-image.js:14:34)
@aron
Copy link
Contributor

aron commented May 2, 2024

@zeke what platform are you running this on? NodeJS?

I think the solution here is to merge #184 and utilize the file upload endpoint, I hadn't realized it hasn't been merged yet. @mattt what are your thoughts?

@mattt
Copy link
Member

mattt commented May 2, 2024

@aron Yeah, I think the Files API would be the best solution to this. Let's chat about what's blocking us from shipping that.

@zeke
Copy link
Member Author

zeke commented May 2, 2024

I hadn't realized it hasn't been merged yet.

Ah yeah same.. I was thinking, "Isn't this file supposed to be uploaded automatically by the client now?" That explains it.

Files API sounds good to me. 👍🏼

@armenavanesi
Copy link

armenavanesi commented May 11, 2024

Hey any updates on when this fix will be merged? I'm following the upload guide that can be accessed from any model and neither File, Blob, and Buffer uploads all give me this error. Thanks

@EvansUchwa
Copy link

Hey any updates on when this fix will be merged? I'm following the upload guide that can be accessed from any model and neither File, Blob, and Buffer uploads all give me this error. Thanks

Hello, I also have the same problem. Were you able to find a solution?

@zeke
Copy link
Member Author

zeke commented May 13, 2024

We're going to ship #184, but in the short term you can temporarily work around it by npm installing this branch from GitHub:

npm install replicate/replicate-javascript#fix-rangeerror

@EvansUchwa
Copy link

We're going to ship #184, but in the short term you can temporarily work around it by npm installing this branch from GitHub:

npm install replicate/replicate-javascript#fix-rangeerror

Thanks a lot ,you saved my life🙏🏿

@geronimi73
Copy link

We're going to ship #184, but in the short term you can temporarily work around it by npm installing this branch from GitHub:

npm install replicate/replicate-javascript#fix-rangeerror

Thanks a lot ,you saved my life🙏🏿

mine too. please ship this PR

@zeke
Copy link
Member Author

zeke commented May 22, 2024

@mattt just landed v0.30.0 with support for automatically uploading your file inputs and turning them into URL inputs to your predictions. That should solve this issue!

To use it:

npm install replicate@latest

@zeke zeke closed this as completed May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants