(
x: Argument,
)
| 238 | ) -> None: |
| 239 | # propagate the fake tensor or sym nodes |
| 240 | def make_val( |
| 241 | x: Argument, |
| 242 | ) -> Union[ |
| 243 | FakeTensor, |
| 244 | torch.SymInt, |
| 245 | torch.SymFloat, |
| 246 | torch.SymBool, |
| 247 | int, |
| 248 | float, |
| 249 | bool, |
| 250 | str, |
| 251 | None, |
| 252 | ]: |
| 253 | if isinstance(x, FakeTensor): |
| 254 | return x |
| 255 | elif isinstance(x, torch.Tensor): |
| 256 | if x.is_quantized: |
| 257 | # TODO (tmanlaibaatar) properly support Quantized FakeTensor |
| 258 | x = torch.dequantize(x) |
| 259 | |
| 260 | try: |
| 261 | assert self.fake_tensor_mode is not None |
| 262 | # TODO we should allocate static shapes |
| 263 | # for param/buffer values |
| 264 | if isinstance(x, torch.nn.Parameter): |
| 265 | fake_tensor = self.fake_tensor_mode.from_tensor( |
| 266 | x, static_shapes=True |
| 267 | ) |
| 268 | else: |
| 269 | fake_tensor = self.fake_tensor_mode.from_tensor(x) |
| 270 | except UnsupportedFakeTensorException: |
| 271 | # TODO: This is just a workaround to get over the |
| 272 | # x.as_subclass error |
| 273 | print( |
| 274 | "Fakeifying a Tensor subclass is not supported \ |
| 275 | right now. Instead a TensorMetadata is used." |
| 276 | ) |
| 277 | fake_tensor = None |
| 278 | return fake_tensor |
| 279 | elif isinstance( |
| 280 | x, |
| 281 | ( |
| 282 | torch.SymInt, |
| 283 | torch.SymFloat, |
| 284 | torch.SymBool, |
| 285 | int, |
| 286 | float, |
| 287 | bool, |
| 288 | str, |
| 289 | ), |
| 290 | ): |
| 291 | return x |
| 292 | else: |
| 293 | return None |
| 294 | |
| 295 | node.meta["val"] = pytree.tree_map(make_val, value) |
| 296 |
nothing calls this directly
no test coverage detected