GithubHelp home page GithubHelp logo

Move input_ids to CUDA about jsonformer HOT 3 CLOSED

1rgs avatar 1rgs commented on July 17, 2024
Move input_ids to CUDA

from jsonformer.

Comments (3)

OmarMohammed88 avatar OmarMohammed88 commented on July 17, 2024

can you share the code u used?

from jsonformer.

anujnayyar1 avatar anujnayyar1 commented on July 17, 2024
from jsonformer import Jsonformer
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

tokenizer = AutoTokenizer.from_pretrained("StabilityAI/stablelm-base-alpha-7b")
model = AutoModelForCausalLM.from_pretrained("StabilityAI/stablelm-base-alpha-7b")
model.half().cuda()

json_schema = {
    "type": "object",
    "properties": {
        "name": {"type": "string"},
        "age": {"type": "number"},
        "is_student": {"type": "boolean"},
        "courses": {
            "type": "array",
            "items": {"type": "string"}
        }
    }
}

prompt = "Generate a person's information based on the following schema:"
jsonformer = Jsonformer(model, tokenizer, json_schema, prompt)
generated_data = jsonformer()

print(generated_data)

To alleviate this problem I have tried loading through:
model = AutoModelForCausalLM.from_pretrained("StabilityAI/stablelm-base-alpha-7b", device_map="auto", torch_dtype=torch.float16)

Which seems to load better but then I run into the following:

IndexError                                Traceback (most recent call last)
Cell In[10], line 23
     21 prompt = "Generate a person's information based on the following schema:"
     22 jsonformer = Jsonformer(model, tokenizer, json_schema, prompt)
---> 23 generated_data = jsonformer()
     25 print(generated_data)

File /opt/conda/lib/python3.10/site-packages/jsonformer/main.py:188, in Jsonformer.__call__(self)
    185 def __call__(self) -> Dict[str, Any]:
    186     self.value = {}
--> 188     generated_data = self.generate_object(
    189         self.json_schema["properties"], self.value
    190     )
    191     return generated_data

File /opt/conda/lib/python3.10/site-packages/jsonformer/main.py:114, in Jsonformer.generate_object(self, properties, obj)
    109 def generate_object(
    110     self, properties: Dict[str, Any], obj: Dict[str, Any]
    111 ) -> Dict[str, Any]:
    112     # self.debug("[generate_object] properties", properties)
    113     for key, schema in properties.items():
--> 114         obj[key] = self.generate_value(schema, obj, key)
    115     return obj

File /opt/conda/lib/python3.10/site-packages/jsonformer/main.py:136, in Jsonformer.generate_value(self, schema, obj, key)
    134     new_array = []
    135     obj[key] = new_array
--> 136     return self.generate_array(schema["items"], new_array)
    137 elif schema_type == "object":
    138     new_obj = {}

File /opt/conda/lib/python3.10/site-packages/jsonformer/main.py:146, in Jsonformer.generate_array(self, item_schema, obj)
    144 def generate_array(self, item_schema: Dict[str, Any], obj: Dict[str, Any]) -> list:
    145     for _ in range(self.max_array_length):
--> 146         element = self.generate_value(item_schema, obj)
    147         obj[-1] = element
    149         obj.append(self.generation_marker)

File /opt/conda/lib/python3.10/site-packages/jsonformer/main.py:131, in Jsonformer.generate_value(self, schema, obj, key)
    129     return self.generate_boolean()
    130 elif schema_type == "string":
--> 131     obj[key if key else -1] = self.generation_marker
    132     return self.generate_string()
    133 elif schema_type == "array":

IndexError: list assignment index out of range

from jsonformer.

1rgs avatar 1rgs commented on July 17, 2024

@anujnayyar1 this should be fixed in the latest release, thanks!

from jsonformer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.