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

Instantiate multiple instances of resource clients when a closure repeatedly accesses the same resource object #136

Open
jianzs opened this issue Feb 28, 2024 · 0 comments
Labels
bug Something isn't working deducer Deducer

Comments

@jianzs
Copy link
Contributor

jianzs commented Feb 28, 2024

In the current deduction system, multiple accesses to the same resource object within a closure do not result in reduced dependencies. This leads to attempts at creating several clients for the identical resource object, resulting in more than one variable with the same name.

Take this as an example: we call both invoke and endpointUrl methods of a single sagemaker object within one router handler. The deducer identifies two dependencies related to this sagemaker object for the router handler's corresponding compute closure. One is classified as a client API dependency while the other is seen as a captured property dependency. When extracting this closure into a separate directory, it's necessary for our deducer to create a sagemaker client. Ideally, only one such client should be created; however, currently two identical ones are being generated instead. This causes exceptions during runtime on cloud platforms.

router.post("/generate", async (req) => {
  console.log("the endpoint url of the sagemaker model is", sagemaker.endpointUrl());

  const payload = req.body;
  if (!payload) {
    return {
      statusCode: 400,
      body: "The request body is empty. Please provide a valid input.",
    };
  }

  const data = JSON.parse(payload);
  if (!data["inputs"]) {
    // The payload should be a JSON object with a key "inputs".
    return {
      statusCode: 400,
      body: "The request body is invalid. Please provide a valid input.",
    };
  }

  // Invoke the SageMaker endpoint with the input data and return the response to the users.
  const output = await sagemaker.invoke(data);
  return {
    statusCode: 200,
    body: JSON.stringify(output),
  };
});
@jianzs jianzs added bug Something isn't working deducer Deducer labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working deducer Deducer
Projects
None yet
Development

No branches or pull requests

1 participant