ML Frameworks & Libraries
The libraries you actually build and ship models with: PyTorch and TensorFlow for deep learning, Keras as the high-level API, scikit-learn for classical ML, OpenCV for vision, and the runtimes that run models on device. Interviews expect fluency in at least one stack and awareness of what the others trade away.
on this pageshowhide
explore
- PyTorch37 questions
- Tensors and Operations6 questions
- Autograd and Gradients6 questions
- nn.Module and Layers6 questions
- Training Loops and Optimizers7 questions
- Data Loading and Pipelines6 questions
- TorchScript and Deployment6 questions
- TensorFlow35 questions
- Tensors and Graphs6 questions
- tf.data Pipelines6 questions
- Keras API4 questions
- Training and Optimization7 questions
- Distributed Training6 questions
- SavedModel and Serving6 questions
- Keras30 questions
- Sequential, Functional & Subclassing6 questions
- Layers and Custom Layers6 questions
- compile / fit and Custom Steps6 questions
- Callbacks6 questions
- Saving and Multi-Backend6 questions
- Scikit-learn36 questions
- Estimator API6 questions
- Preprocessing & Features6 questions
- Pipelines6 questions
- Model Selection & CV6 questions
- Supervised Estimators6 questions
- Metrics & Evaluation6 questions
- OpenCV36 questions
- Image I/O and Color6 questions
- Filtering and Transforms6 questions
- Feature Detection6 questions
- Contours and Morphology6 questions
- Video Processing6 questions
- DNN Module6 questions
- On-Device PyTorch (ExecuTorch)12 questions
- Export and On-Device Runtime6 questions
- Quantization for Mobile6 questions
- TFLite12 questions
- Conversion and Quantization6 questions
- Interpreter and Delegates6 questions
questions
198 · 7 sectionsIn PyTorch, what does requires_grad=True do to a tensor?
basics
~10 srequires_grad=True tells PyTorch to record every operation that uses the tensor, so a backward pass can compute a derivative with respect to it. After backward(), the gradient shows up in that tensor's .grad attribute.
In PyTorch, what must a custom map-style Dataset implement, and what does DataLoader add?
basics
~10 sA map-style Dataset implements len, returning the number of samples, and getitem(index), returning one sample (often a tensor/label tuple). DataLoader wraps it and produces shuffled, collated mini-batches, optionally loaded by worker processes.
How do you load a GPU-trained PyTorch checkpoint on a CPU-only inference box?
basics
~20 sPass map_location to torch.load, for example torch.load(path, map_location="cpu"), so saved tensors are restored onto the CPU instead of the CUDA device they were saved from. Then load_state_dict into a model and move the model once with .to(device).
In PyTorch, why call model(x) instead of model.forward(x)?
basics
~10 sCalling the module runs nn.Module.call, which fires registered forward pre-hooks and forward hooks around forward(). Calling model.forward(x) directly skips all of that machinery, so hook-based features silently stop working.
Does torch.from_numpy() copy the NumPy array or share memory with it?
basics
~10 storch.from_numpy() shares the array's buffer, so writing through either side is visible to the other. torch.tensor(arr) always copies. Tensor.numpy() shares as well, and only works for CPU tensors.
Under tf.distribute MirroredStrategy, is model.fit's batch_size global or per GPU?
basics
~10 sGlobal. Keras splits each batch evenly across the replicas, so batch_size=256 on four GPUs means 64 examples per GPU per step. To keep per-GPU work constant, raise the global number as you add devices.
How do you send a prediction request to TensorFlow Serving's REST API?
basics
~10 sPOST JSON to http://host:8501/v1/models/MODEL:predict with an "instances" list of examples; the response is a JSON object with a "predictions" list in the same order. Port 8501 is REST; 8500 is gRPC.
Why does tf.data.Dataset.prefetch(tf.data.AUTOTUNE) go last in a pipeline?
basics
~20 sprefetch decouples producing elements from consuming them: a background thread fills a buffer while the accelerator trains on the previous batch. Placed last, after batch, its buffer holds ready-to-use batches, so step N+1's input work overlaps step N's compute.
In tf.data, what does shuffle(buffer_size) actually do, and why does its position matter?
basics
~20 stf.data's shuffle keeps a buffer of buffer_size elements, emits one at random from it, and refills the slot from the source. It is a sliding-window shuffle, not a global one, so a small buffer over sorted data barely mixes anything.
What must be created inside a tf.distribute strategy.scope(), and why?
basics
~20 sAnything that creates variables: the model, the optimizer, and any metric or custom tf.Variable. Inside the scope those become mirrored variables with one synchronized copy per replica. Datasets, fit calls, and the training step itself go outside.
In Keras, what does ModelCheckpoint(save_best_only=True) change about when a file is written?
basics
~20 sWith save_best_only=True, ModelCheckpoint writes a file only on epochs where the monitored value improves on the best seen so far. With the default False it writes every epoch. The monitored value is named by the monitor argument, which defaults to val_loss.
In Keras, what does Dense(64) output for an input of shape (32, 10, 8)?
basics
~20 sShape (32, 10, 64). A Dense layer transforms only the last axis, reusing one kernel of shape (8, 64) at every one of the 10 positions, so it holds 8 * 64 + 64 = 576 parameters no matter the batch or sequence length.
In Keras, when is Sequential not enough and you need the Functional API?
basics
~20 skeras.Sequential models a straight stack: one input, one output, each layer feeding the next. Anything with branches, several inputs or outputs, skip connections, or one layer instance reused twice needs the Functional API, which wires an explicit graph of layer calls.
In Keras 3, what does model.save('model.keras') store and how do you load it?
basics
~10 smodel.save('model.keras') writes one zip archive holding the architecture config, the weights and the optimizer state. keras.saving.load_model('model.keras') rebuilds the whole model, ready to predict or resume training without re-running the build code.
In Keras, what does model.compile() configure before you call fit()?
basics
~20 smodel.compile() attaches the training configuration to a model: the optimizer that updates the weights, the loss that fit() minimises, and the metrics reported each epoch. Until you call it, fit() and evaluate() have nothing to optimise and raise an error.
In scikit-learn, what does a trailing underscore in coef_ or mean_ mean?
basics
~20 sA trailing underscore marks state learned during fit, such as coef_, mean_ or n_features_in_. It does not exist on a freshly constructed estimator, and check_is_fitted uses the presence of such attributes to decide whether the estimator has been fitted.
In scikit-learn, how do you read the output of confusion_matrix?
basics
~20 sconfusion_matrix returns a square array where rows are true classes and columns are predicted classes, so C[i, j] counts samples of true class i predicted as class j. Classes appear in sorted order unless you pass labels= to fix the order.
In scikit-learn, what does the stratify argument of train_test_split do?
basics
~20 sstratify=y tells train_test_split to preserve each class's proportion in both halves instead of splitting purely at random. Without it a rare class can land unevenly in the test set, or be missing from it entirely.
In scikit-learn, what happens at each step when you call Pipeline.fit() then predict()?
basics
~20 sfit runs fit_transform on every step except the last, feeding each output into the next, then fit on the final estimator. predict runs transform only on those same intermediate steps — never fit again — and calls predict on the final estimator.
When is scikit-learn's OrdinalEncoder a safe choice instead of OneHotEncoder?
basics
~20 sOrdinalEncoder maps each category to an integer in one column, which implies an ordering. That is safe for genuinely ordered features and for tree-based models that split on thresholds, but misleading for linear models, SVMs and distance-based estimators.
In OpenCV, what input does cv2.findContours require and what does it return?
basics
~20 scv2.findContours expects a single-channel 8-bit binary image with white objects on a black background - every non-zero pixel counts as foreground. In OpenCV 4 and 5 it returns two values: a list of contours and a hierarchy array.
How do you load an ONNX model with cv2.dnn and run one inference?
basics
~10 sCall cv2.dnn.readNet("model.onnx") (or readNetFromONNX), build a blob with cv2.dnn.blobFromImage, pass it in with net.setInput(blob), then call net.forward() to get the output array. No training framework is needed at runtime.
In OpenCV, what does detectAndCompute() return for a detector like SIFT or ORB?
basics
~20 sdetectAndCompute returns a two-element tuple: a list of cv2.KeyPoint objects and a NumPy descriptor array with one row per keypoint. Row i describes keypoints[i]. When nothing is detected, the descriptor value is None, not an empty array.
Which cv2.resize interpolation flag should you use when downscaling, and why?
basics
~20 sUse cv2.INTER_AREA. It averages over the source pixel area that maps to each output pixel, so detail is integrated rather than skipped. The default cv2.INTER_LINEAR samples only a few points and produces aliasing and moire on large reductions.
Why do images read with cv2.imread() look blue when shown by matplotlib?
basics
~10 scv2.imread() returns pixels in BGR channel order, while matplotlib's imshow expects RGB. The first and third channels are interpreted swapped, so reds render as blues. Convert first with cv2.cvtColor(img, cv2.COLOR_BGR2RGB).
Why does a data-dependent if in forward() break torch.export for on-device use?
basics
~20 sExport captures one static graph, so a branch whose condition is a tensor value either fails with a data-dependent guard error or gets frozen to whichever side the example input took. The device runtime has no Python to re-evaluate it.
How does a PyTorch nn.Module become an ExecuTorch .pte file?
basics
~20 sThree ahead-of-time steps: torch.export.export captures the model as an ExportedProgram graph, to_edge_transform_and_lower converts it to the Edge dialect and hands supported subgraphs to a backend, and to_executorch emits the flatbuffer you write out as .pte.
Why does PT2 export quantization need a backend quantizer like XNNPACKQuantizer?
basics
~20 sBecause only the backend knows which operator patterns it can actually execute in int8. The quantizer encodes that contract, annotating exactly the nodes the delegate can fuse; quantizing anything else adds quantize/dequantize work around an op that still runs in float.
In ExecuTorch int8 quantization, when do you need calibration data?
basics
~20 sOnly for static quantization, where activation scales are frozen ahead of time and must come from observed data. Dynamic quantization quantizes weights offline and computes activation scales at runtime per input, so no calibration set is required.
What do prepare_pt2e and convert_pt2e do to an exported PyTorch graph?
basics
~20 sprepare_pt2e inserts observer modules at the tensors a quantizer annotated, so a calibration or training run records their value ranges. convert_pt2e then replaces each observer with quantize/dequantize op pairs carrying the scale and zero-point it computed.
How do you convert a TensorFlow SavedModel into a .tflite file with tf.lite.TFLiteConverter?
basics
~10 sBuild a converter with tf.lite.TFLiteConverter.from_saved_model(path), then call convert(). It returns the model as a bytes FlatBuffer that you write to a .tflite file yourself. Nothing is quantized unless you set converter.optimizations.
In LiteRT, what calls does a minimal Interpreter inference pass need?
basics
~10 sConstruct the Interpreter with the .tflite file, call allocate_tensors(), read the input's index from get_input_details(), set_tensor(index, data), invoke(), then get_tensor() on the output index. Without allocate_tensors() there are no buffers to write into.
Which tf.lite post-training quantization modes require a representative_dataset, and why?
basics
~20 sOnly full-integer quantization needs converter.representative_dataset. Dynamic-range and float16 touch weights alone, which the converter can read from the file. Integer activations need real sample inputs so the converter can observe each tensor's value range and pick a scale and zero-point.
In LiteRT, what happens to ops a GPU or NNAPI delegate cannot run?
basics
~20 sThe graph is partitioned. The delegate claims the largest contiguous runs of ops it supports; everything else stays on CPU kernels. Nothing errors — but each partition boundary copies tensors between CPU and accelerator memory, so a fragmented graph can run slower than pure CPU.
In TFLite conversion, what changes when you set converter.inference_input_type to tf.int8?
basics
~20 sIt removes the float boundary. By default even a fully quantized model exposes float32 input and output with quantize/dequantize ops at the edges; setting inference_input_type (and inference_output_type) to tf.int8 makes the model take and return raw integers, so the caller must apply the recorded scale and zero-point itself.