MCPcopy Create free account
hub / github.com/RightNow-AI/autokernel / make_model_input

Function make_model_input

verify.py:230–251  ·  view source on GitHub ↗

Create an appropriate input for the model.

(
    model: nn.Module,
    input_shape: str,
    dtype: torch.dtype,
    device: str = "cuda",
)

Source from the content-addressed store, hash-verified

228
229
230def make_model_input(
231 model: nn.Module,
232 input_shape: str,
233 dtype: torch.dtype,
234 device: str = "cuda",
235) -> Union[torch.Tensor, Dict[str, torch.Tensor]]:
236 """Create an appropriate input for the model."""
237 input_type = infer_input_type(model)
238
239 if input_type == "token_ids":
240 # Language model: expects integer input_ids
241 dims = [int(d.strip()) for d in input_shape.split(",")]
242 torch.manual_seed(42)
243 input_ids = torch.randint(0, 32000, dims, device=device, dtype=torch.long)
244
245 # Check if model accepts input_ids keyword
246 sig = inspect.signature(model.forward)
247 if "input_ids" in sig.parameters:
248 return {"input_ids": input_ids}
249 return input_ids
250 else:
251 return generate_sample_input(input_shape, dtype, device)
252
253
254# ---------------------------------------------------------------------------

Callers 1

mainFunction · 0.85

Calls 2

infer_input_typeFunction · 0.85
generate_sample_inputFunction · 0.85

Tested by

no test coverage detected